bash-stuff/backup-image/restore.sh

32 lines
986 B
Bash
Executable File

#!/bin/bash
echo "Disk Restore!";
if [ $# -eq 0 ]; then
echo "Usage: restore.sh <Backup disk name> <Block Device in /dev>";
exit 2;
fi
echo "Destination Disk: /dev/$2";
echo "Source Backup Name: $1";
echo "Press Enter to Start...";
read;
mkdir -p /tmp/a;
gunzip -c "/mnt/parts/$1.part.gz" | dd "of=/dev/$2" status=progress conv=sync,noerror;
echo "Calculating SHA512 sums...";
(sha512sum "/dev/$2" > "/tmp/a/$2.sum") && dd "if=/tmp/a/$2.sum" bs=128 count=1 "of=/tmp/a/$2.hash";
cmp -s "/tmp/a/$2.hash" "/mnt/hsums/$1.hash";
if [ $? -ne 0 ]; then
echo "Hashes do not match!";
exit 1;
fi
(sha512sum "/mnt/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" "/mnt/hsums/$1-tbl.hash";
if [ $? -ne 0 ]; then
echo "Partition hashes do not match!";
exit 1;
fi
echo;
echo "Restoring up partition table...";
sfdisk "/dev/$2" < "/mnt/tabls/$1.tbl";
rm -rf /tmp/a;
echo "Finished!";
exit 0;