bash-stuff/backup-image/verify.sh

41 lines
1.2 KiB
Bash
Raw Permalink 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
2024-08-30 11:15:29 +01:00
mkdir -p /tmp/a;
echo "Verifying...";
echo "Calculating SHA512 sums...";
((sha512sum "$ssrc/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" && touch "/tmp/a/1.complete") &
2024-08-30 13:16:28 +01:00
((sha512sum "$ssrc/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" && touch "/tmp/a/2.complete") &
2024-08-30 11:15:29 +01:00
until [ -f "/tmp/a/1.complete" ] && [ -f "/tmp/a/2.complete" ]; do sleep 0.1; done;
echo "Hashes:";
cat /tmp/a/*.sum;
echo;
cmp -s "/tmp/a/$1-gz.hash" "$ssrc/hsums/$1-gz.hash";
if [ $? -ne 0 ]; then
echo "Hash mismatch with $1.part.gz !";
exit 1;
fi
cmp -s "/tmp/a/$1-tbl.hash" "$ssrc/hsums/$1-tbl.hash";
if [ $? -ne 0 ]; then
echo "Hash mismatch with $1.tbl !";
exit 1;
fi
rm -rf /tmp/a;
echo "Finished!";
exit 0;