Add my imaging backup script.
This commit is contained in:
parent
fc7f0b5c75
commit
c85918a065
33
backup-image/backup.sh
Executable file
33
backup-image/backup.sh
Executable file
@ -0,0 +1,33 @@
|
||||
#!/bin/bash
|
||||
echo "Disk Backup!";
|
||||
if [ $# -eq 0 ]; then
|
||||
echo "Usage: backup.sh <Block Device in /dev> <Backup disk name>";
|
||||
exit 2;
|
||||
fi
|
||||
echo "Source Disk: /dev/$1";
|
||||
echo "Destination Name: $2";
|
||||
echo "Press Enter to Start...";
|
||||
read;
|
||||
mkdir -p /tmp/a;
|
||||
dd "if=/dev/$1" status=progress conv=sync,noerror | gzip -6 -c > "/mnt/parts/$2.part.gz";
|
||||
echo "Calculating SHA512 sums...";
|
||||
((sha512sum "/dev/$1" > "/tmp/a/$1.sum") && dd "if=/tmp/a/$1.sum" bs=128 count=1 "of=/tmp/a/$1.hash" && touch "/tmp/a/1.complete") &
|
||||
((sha512sum "/mnt/parts/$2.part.gz" > "/tmp/a/$2.part.gz.sum") && dd "if=/tmp/a/$2.part.gz.sum" bs=128 count=1 "of=/tmp/a/$2-gz.hash" && touch "/tmp/a/2.complete") &
|
||||
((gunzip -c "/mnt/parts/$2.part.gz" | sha512sum > "/tmp/a/$2.part.sum") && dd "if=/tmp/a/$2.part.sum" bs=128 count=1 "of=/tmp/a/$2.hash" && touch "/tmp/a/3.complete") &
|
||||
until [ -f "/tmp/a/1.complete" ] && [ -f "/tmp/a/2.complete" ] && [ -f "/tmp/a/3.complete" ]; do sleep 0.1; done;
|
||||
echo "Hashes:";
|
||||
cat "/tmp/a/*.sum";
|
||||
echo;
|
||||
cmp -s "/tmp/a/$1.hash" "/tmp/a/$2.hash";
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Hashes do not match!";
|
||||
exit 1;
|
||||
fi
|
||||
cp -f "/tmp/a/$2-gz.hash" "/mnt/hsums/$2-gz.hash";
|
||||
cp -f "/tmp/a/$2.hash" "/mnt/hsums/$2.hash";
|
||||
echo;
|
||||
rm -rf /tmp/a;
|
||||
echo "Backing up partition table...";
|
||||
sfdisk -d "/dev/$1" > "/mnt/tabls/$2.tbl";
|
||||
echo "Finished!";
|
||||
exit 0;
|
Loading…
Reference in New Issue
Block a user