54 lines
1.7 KiB
Bash
Raw Normal View History

2024-08-30 11:15:29 +01:00
#!/bin/bash
echo "Verify Backup!";
if [ $# -eq 0 ]; then
echo "Usage: verify.sh <Backup disk name> [Storage disk root path]";
exit 2;
fi
ssrc="";
if [ -z $2 ]; then
ssrc="/mnt";
else
ssrc="$2";
fi
echo "Source Backup disk name: $1";
2024-08-30 13:16:28 +01:00
echo "Storage disk root path: $ssrc";
if [[ "$3" != "ikwid" ]]; then
echo "Press Enter to Start...";
read;
fi
uuidTmp="/tmp/a-$(uuidgen)";
mkdir -p $uuidTmp;
2024-08-30 11:15:29 +01:00
echo "Verifying...";
echo "Calculating SHA512 sums...";
((sha512sum "$ssrc/parts/$1.part.gz" > "$uuidTmp/$1.part.gz.sum") && dd "if=$uuidTmp/$1.part.gz.sum" bs=128 count=1 "of=$uuidTmp/$1-gz.hash" && touch "$uuidTmp/1.complete") &
((sha512sum "$ssrc/tabls/$1.tbl" > "$uuidTmp/$1.tbl.sum") && dd "if=$uuidTmp/$1.tbl.sum" bs=128 count=1 "of=$uuidTmp/$1-tbl.hash" && touch "$uuidTmp/2.complete") &
2025-02-23 14:52:29 +00:00
if [ -f "$ssrc/times/$1.time" ]; then
((sha512sum "$ssrc/times/$1.time" > "$uuidTmp/$1.time.sum") && dd "if=$uuidTmp/$1.time.sum" bs=128 count=1 "of=$uuidTmp/$1-time.hash" && touch "$uuidTmp/3.complete") &
2025-02-23 14:52:29 +00:00
else
touch "$uuidTmp/3.complete";
2025-02-23 14:52:29 +00:00
fi
until [ -f "$uuidTmp/1.complete" ] && [ -f "$uuidTmp/2.complete" ] && [ -f "$uuidTmp/3.complete" ]; do sleep 0.1; done;
2024-08-30 11:15:29 +01:00
echo "Hashes:";
cat $uuidTmp/*.sum;
2024-08-30 11:15:29 +01:00
echo;
cmp -s "$uuidTmp/$1-gz.hash" "$ssrc/hsums/$1-gz.hash";
2024-08-30 11:15:29 +01:00
if [ $? -ne 0 ]; then
echo "Hash mismatch with $1.part.gz !";
exit 1;
fi
cmp -s "$uuidTmp/$1-tbl.hash" "$ssrc/hsums/$1-tbl.hash";
2024-08-30 11:15:29 +01:00
if [ $? -ne 0 ]; then
echo "Hash mismatch with $1.tbl !";
exit 1;
fi
2025-02-23 14:52:29 +00:00
if [ -f "$ssrc/times/$1.time" ]; then
cmp -s "$uuidTmp/$1-time.hash" "$ssrc/hsums/$1-time.hash";
2025-02-23 14:52:29 +00:00
if [ $? -ne 0 ]; then
echo "Hash mismatch with $1.time !";
exit 1;
fi
fi
rm -rf $uuidTmp;
2024-08-30 11:15:29 +01:00
echo "Finished!";
exit 0;