54 lines
1.7 KiB
Bash
Executable File

#!/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";
echo "Storage disk root path: $ssrc";
if [[ "$3" != "ikwid" ]]; then
echo "Press Enter to Start...";
read;
fi
uuidTmp="/tmp/a-$(uuidgen)";
mkdir -p $uuidTmp;
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") &
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") &
else
touch "$uuidTmp/3.complete";
fi
until [ -f "$uuidTmp/1.complete" ] && [ -f "$uuidTmp/2.complete" ] && [ -f "$uuidTmp/3.complete" ]; do sleep 0.1; done;
echo "Hashes:";
cat $uuidTmp/*.sum;
echo;
cmp -s "$uuidTmp/$1-gz.hash" "$ssrc/hsums/$1-gz.hash";
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";
if [ $? -ne 0 ]; then
echo "Hash mismatch with $1.tbl !";
exit 1;
fi
if [ -f "$ssrc/times/$1.time" ]; then
cmp -s "$uuidTmp/$1-time.hash" "$ssrc/hsums/$1-time.hash";
if [ $? -ne 0 ]; then
echo "Hash mismatch with $1.time !";
exit 1;
fi
fi
rm -rf $uuidTmp;
echo "Finished!";
exit 0;