129 lines
3.4 KiB
Bash
Executable File
129 lines
3.4 KiB
Bash
Executable File
#!/bin/bash
|
|
echo "Sync Backup!";
|
|
if [ $# -eq 0 ]; then
|
|
echo "Usage: sync-btime.sh [o/n/i] <Backup disk name> <Sync target disk root path> [Sync source disk root path]";
|
|
echo "o : Replace if source older"
|
|
echo "n : Replace if source newer"
|
|
echo "i : Ignore backup times"
|
|
exit 2;
|
|
fi
|
|
ssrc="";
|
|
if [ -z $4 ]; then
|
|
ssrc="/mnt";
|
|
else
|
|
ssrc="$4";
|
|
fi
|
|
echo "Source Backup disk name: $2";
|
|
echo "Sync target disk root path: $3";
|
|
echo "Sync source disk root path: $ssrc";
|
|
if [[ "$1" == "o" ]]; then
|
|
echo "Target will be replaced if source older.";
|
|
elif [[ "$1" == "n" ]]; then
|
|
echo "Target will be replaced if source newer.";
|
|
else
|
|
echo "Target will be replaced if different."
|
|
fi
|
|
if [[ "$5" != "ikwid" ]]; then
|
|
echo "Press Enter to Start...";
|
|
read;
|
|
fi
|
|
uuidTmp="/tmp/a-$(uuidgen)";
|
|
mkdir -p $uuidTmp;
|
|
echo "Syncing...";
|
|
cmp -s "$ssrc/hsums/$2-tbl.hash" "$3/hsums/$2-tbl.hash"
|
|
sTbl=$?;
|
|
cmp -s "$ssrc/hsums/$2-gz.hash" "$3/hsums/$2-gz.hash";
|
|
sPart=$?;
|
|
if [ $sPart -eq 0 ]; then
|
|
cmp -s "$ssrc/hsums/$2.hash" "$3/hsums/$2.hash";
|
|
sPart=$?;
|
|
fi
|
|
if [ $sTbl -ne 0 ] || [ $sPart -ne 0 ]; then
|
|
if [[ "$1" == "o" ]]; then
|
|
./btime.sh "$2" "$3" "$4" "ikwid";
|
|
sComp=$?;
|
|
if [ $? -ne 1 ]; then
|
|
sPart=0;
|
|
sTbl=0;
|
|
fi
|
|
elif [[ "$1" == "n" ]]; then
|
|
./btime.sh "$2" "$3" "$4" "ikwid";
|
|
sComp=$?;
|
|
if [ $? -ne 2 ]; then
|
|
sPart=0;
|
|
sTbl=0;
|
|
fi
|
|
fi
|
|
fi
|
|
sO=0;
|
|
if [ $sTbl -ne 0 ]; then
|
|
echo "Syncing: $2.tbl";
|
|
cp -f "$ssrc/tabls/$2.tbl" "$3/tabls/$2.tbl";
|
|
cp -f "$ssrc/hsums/$2-tbl.hash" "$3/hsums/$2-tbl.hash";
|
|
sO=1;
|
|
fi
|
|
if [ $sPart -ne 0 ]; then
|
|
echo "Syncing: $2.part.gz";
|
|
cp -f "$ssrc/hsums/$2-gz.hash" "$3/hsums/$2-gz.hash";
|
|
cp -f "$ssrc/hsums/$2.hash" "$3/hsums/$2.hash";
|
|
cp -f "$ssrc/parts/$2.part.gz" "$3/parts/$2.part.gz";
|
|
sO=1;
|
|
fi
|
|
hT=0;
|
|
if [ $sO -eq 1 ] && [ -f "$ssrc/times/$2.time" ]; then
|
|
echo "Syncing: $2.time";
|
|
cp -f "$ssrc/hsums/$2-time.hash" "$3/hsums/$2-time.hash";
|
|
cp -f "$ssrc/times/$2.time" "$3/times/$2.time";
|
|
hT=1;
|
|
fi
|
|
echo "Verifying...";
|
|
if [ $sTbl -ne 0 ]; then
|
|
echo "Verifying: $2.tbl";
|
|
cmp -s "$ssrc/hsums/$2-tbl.hash" "$3/hsums/$2-tbl.hash";
|
|
if [ $? -ne 0 ]; then
|
|
echo "Hash mismatch with $2-tbl.hash !";
|
|
exit 1;
|
|
fi
|
|
(sha512sum "$3/tabls/$2.tbl" > "$uuidTmp/$2.tbl.sum") && dd "if=$uuidTmp/$2.tbl.sum" bs=128 count=1 "of=$uuidTmp/$2-tbl.hash";
|
|
cmp -s "$uuidTmp/$2-tbl.hash" "$3/hsums/$2-tbl.hash";
|
|
if [ $? -ne 0 ]; then
|
|
echo "Hash mismatch with $2.tbl !";
|
|
exit 1;
|
|
fi
|
|
fi
|
|
if [ $sPart -ne 0 ]; then
|
|
echo "Verifying: $2.part.gz";
|
|
cmp -s "$ssrc/hsums/$2-gz.hash" "$3/hsums/$2-gz.hash";
|
|
if [ $? -ne 0 ]; then
|
|
echo "Hash mismatch with $2-gz.hash !";
|
|
exit 1;
|
|
fi
|
|
cmp -s "$ssrc/hsums/$2.hash" "$3/hsums/$2.hash";
|
|
if [ $? -ne 0 ]; then
|
|
echo "Hash mismatch with $2.hash !";
|
|
exit 1;
|
|
fi
|
|
(sha512sum "$3/parts/$2.part.gz" > "$uuidTmp/$2.part.gz.sum") && dd "if=$uuidTmp/$2.part.gz.sum" bs=128 count=1 "of=$uuidTmp/$2-gz.hash";
|
|
cmp -s "$uuidTmp/$2-gz.hash" "$3/hsums/$2-gz.hash";
|
|
if [ $? -ne 0 ]; then
|
|
echo "Hash mismatch with $2.part.gz !";
|
|
exit 1;
|
|
fi
|
|
fi
|
|
if [ $hT -eq 1 ]; then
|
|
echo "Verifying: $2.time";
|
|
cmp -s "$ssrc/hsums/$2-time.hash" "$3/hsums/$2-time.hash";
|
|
if [ $? -ne 0 ]; then
|
|
echo "Byte mismatch with $2-time.hash !";
|
|
exit 1;
|
|
fi
|
|
cmp -s "$ssrc/times/$2.time" "$3/times/$2.time";
|
|
if [ $? -ne 0 ]; then
|
|
echo "Byte mismatch with $2.time !";
|
|
exit 1;
|
|
fi
|
|
fi
|
|
rm -rf $uuidTmp;
|
|
echo "Finished!";
|
|
exit 0;
|