2024-08-04 16:08:58 +01:00
|
|
|
#!/bin/bash
|
|
|
|
echo "Sync Backup!";
|
|
|
|
if [ $# -eq 0 ]; then
|
2024-08-30 11:15:29 +01:00
|
|
|
echo "Usage: sync.sh <Backup disk name> <Sync target disk root path> [Sync source disk root path]";
|
2024-08-04 16:08:58 +01:00
|
|
|
exit 2;
|
|
|
|
fi
|
2024-08-30 11:15:29 +01:00
|
|
|
ssrc="";
|
|
|
|
if [ -z $3 ]; then
|
|
|
|
ssrc="/mnt";
|
|
|
|
else
|
|
|
|
ssrc="$3";
|
|
|
|
fi
|
2024-08-04 16:08:58 +01:00
|
|
|
echo "Source Backup disk name: $1";
|
2024-08-30 11:15:29 +01:00
|
|
|
echo "Sync target disk root path: $2";
|
|
|
|
echo "Sync source disk root path: $ssrc";
|
2024-08-30 13:16:28 +01:00
|
|
|
if [[ "$4" != "ikwid" ]]; then
|
|
|
|
echo "Press Enter to Start...";
|
|
|
|
read;
|
|
|
|
fi
|
2024-08-04 16:08:58 +01:00
|
|
|
mkdir -p /tmp/a;
|
|
|
|
echo "Syncing...";
|
2024-08-30 13:16:28 +01:00
|
|
|
cmp -s "$ssrc/hsums/$1-tbl.hash" "$2/hsums/$1-tbl.hash"
|
|
|
|
sTbl=$?;
|
|
|
|
cmp -s "$ssrc/hsums/$1-gz.hash" "$2/hsums/$1-gz.hash";
|
|
|
|
sPart=$?;
|
|
|
|
if [ $sPart -eq 0 ]; then
|
|
|
|
cmp -s "$ssrc/hsums/$1.hash" "$2/hsums/$1.hash";
|
|
|
|
sPart=$?;
|
|
|
|
fi
|
|
|
|
if [ $sTbl -ne 0 ]; then
|
|
|
|
echo "Syncing: $1.tbl";
|
|
|
|
cp -f "$ssrc/tabls/$1.tbl" "$2/tabls/$1.tbl";
|
|
|
|
cp -f "$ssrc/hsums/$1-tbl.hash" "$2/hsums/$1-tbl.hash";
|
|
|
|
fi
|
|
|
|
if [ $sPart -ne 0 ]; then
|
|
|
|
echo "Syncing: $1.part.gz";
|
|
|
|
cp -f "$ssrc/hsums/$1-gz.hash" "$2/hsums/$1-gz.hash";
|
|
|
|
cp -f "$ssrc/hsums/$1.hash" "$2/hsums/$1.hash";
|
|
|
|
cp -f "$ssrc/parts/$1.part.gz" "$2/parts/$1.part.gz";
|
|
|
|
fi
|
2024-08-04 16:08:58 +01:00
|
|
|
echo "Verifying...";
|
2024-08-30 13:23:36 +01:00
|
|
|
if [ $sTbl -ne 0 ]; then
|
|
|
|
echo "Verifying: $1.tbl";
|
|
|
|
cmp -s "$ssrc/hsums/$1-tbl.hash" "$2/hsums/$1-tbl.hash";
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "Hash mismatch with $1-tbl.hash !";
|
|
|
|
exit 1;
|
|
|
|
fi
|
|
|
|
(sha512sum "$2/tabls/$1.tbl" > "/tmp/a/$1.tbl.sum") && dd "if=/tmp/a/$1.tbl.sum" bs=128 count=1 "of=/tmp/a/$1-tbl.hash";
|
|
|
|
cmp -s "/tmp/a/$1-tbl.hash" "$2/hsums/$1-tbl.hash";
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "Hash mismatch with $1.tbl !";
|
|
|
|
exit 1;
|
|
|
|
fi
|
2024-08-04 16:08:58 +01:00
|
|
|
fi
|
2024-08-30 13:23:36 +01:00
|
|
|
if [ $sPart -ne 0 ]; then
|
|
|
|
echo "Verifying: $1.part.gz";
|
|
|
|
cmp -s "$ssrc/hsums/$1-gz.hash" "$2/hsums/$1-gz.hash";
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "Hash mismatch with $1-gz.hash !";
|
|
|
|
exit 1;
|
|
|
|
fi
|
|
|
|
cmp -s "$ssrc/hsums/$1.hash" "$2/hsums/$1.hash";
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "Hash mismatch with $1.hash !";
|
|
|
|
exit 1;
|
|
|
|
fi
|
|
|
|
(sha512sum "$2/parts/$1.part.gz" > "/tmp/a/$1.part.gz.sum") && dd "if=/tmp/a/$1.part.gz.sum" bs=128 count=1 "of=/tmp/a/$1-gz.hash";
|
|
|
|
cmp -s "/tmp/a/$1-gz.hash" "$2/hsums/$1-gz.hash";
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "Hash mismatch with $1.part.gz !";
|
|
|
|
exit 1;
|
|
|
|
fi
|
2024-08-04 16:08:58 +01:00
|
|
|
fi
|
|
|
|
rm -rf /tmp/a;
|
|
|
|
echo "Finished!";
|
|
|
|
exit 0;
|