bash-stuff/backup-image/restore.sh

32 lines
986 B
Bash
Raw Permalink Normal View History

2024-08-30 11:15:29 +01:00
#!/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
2024-08-30 13:16:28 +01:00
(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";
2024-08-30 11:15:29 +01:00
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...";
2024-09-02 16:20:09 +01:00
sfdisk "/dev/$2" < "/mnt/tabls/$1.tbl";
2024-08-30 11:15:29 +01:00
rm -rf /tmp/a;
echo "Finished!";
exit 0;