bash-stuff/backup-image/copy.sh

52 lines
1.4 KiB
Bash
Executable File

#!/bin/bash
echo "Copy Backup!";
if [ $# -eq 0 ]; then
echo "Usage: copy.sh <Backup disk name> <Copied Backup disk name> [Storage disk root path]";
exit 2;
fi
ssrc="";
if [ -z $3 ]; then
ssrc="/mnt";
else
ssrc="$3";
fi
echo "Source Backup disk name: $1";
echo "Target Backup disk name: $2";
echo "Storage disk root path: $ssrc";
echo "Press Enter to Start...";
read;
echo "Copying...";
cp -f "$ssrc/hsums/$1-gz.hash" "$ssrc/hsums/$2-gz.hash";
cp -f "$ssrc/hsums/$1-tbl.hash" "$ssrc/hsums/$2-tbl.hash";
cp -f "$ssrc/hsums/$1.hash" "$ssrc/hsums/$2.hash";
cp -f "$ssrc/parts/$1.part.gz" "$ssrc/parts/$2.part.gz";
cp -f "$ssrc/tabls/$1.tbl" "$ssrc/tabls/$2.tbl";
echo "Verifying...";
cmp -s "$ssrc/hsums/$1-gz.hash" "$ssrc/hsums/$2-gz.hash";
if [ $? -ne 0 ]; then
echo "Byte mismatch with $1-gz.hash !";
exit 1;
fi
cmp -s "$ssrc/hsums/$1-tbl.hash" "$ssrc/hsums/$2-tbl.hash";
if [ $? -ne 0 ]; then
echo "Byte mismatch with $1-tbl.hash !";
exit 1;
fi
cmp -s "$ssrc/hsums/$1.hash" "$ssrc/hsums/$2.hash";
if [ $? -ne 0 ]; then
echo "Byte mismatch with $1.hash !";
exit 1;
fi
cmp -s "$ssrc/parts/$1.part.gz" "$ssrc/parts/$2.part.gz";
if [ $? -ne 0 ]; then
echo "Byte mismatch with $1.part.gz !";
exit 1;
fi
cmp -s "$ssrc/tabls/$1.tbl" "$ssrc/tabls/$2.tbl";
if [ $? -ne 0 ]; then
echo "Byte mismatch with $1.tbl !";
exit 1;
fi
echo "Finished!";
exit 0;