Add more backup management scripts.

This commit is contained in:
Captain ALM 2024-08-30 11:15:29 +01:00
parent 6d8a93a5f3
commit 837d75d003
Signed by: alfred
GPG Key ID: 4E4ADD02609997B1
6 changed files with 186 additions and 11 deletions

51
backup-image/copy.sh Executable file
View File

@ -0,0 +1,51 @@
#!/bin/bash
echo "Copy Backup!";
if [ $# -eq 0 ]; then
echo "Usage: copy.sh <Backup disk name> <Copied Backup disk name> [Storage disk root path]";
exit 2;
fi
ssrc="";
if [ -z $3 ]; then
ssrc="/mnt";
else
ssrc="$3";
fi
echo "Source Backup disk name: $1";
echo "Target Backup disk name: $2";
echo "Sync storage disk root path: $ssrc";
echo "Press Enter to Start...";
read;
echo "Copying...";
cp -f "$ssrc/hsums/$1-gz.hash" "$ssrc/hsums/$2-gz.hash";
cp -f "$ssrc/hsums/$1-tbl.hash" "$ssrc/hsums/$2-tbl.hash";
cp -f "$ssrc/hsums/$1.hash" "$ssrc/hsums/$2.hash";
cp -f "$ssrc/parts/$1.part.gz" "$ssrc/parts/$2.part.gz";
cp -f "$ssrc/tabls/$1.tbl" "$ssrc/tabls/$2.tbl";
echo "Verifying...";
cmp -s "$ssrc/hsums/$1-gz.hash" "$ssrc/hsums/$2-gz.hash";
if [ $? -ne 0 ]; then
echo "Byte mismatch with $1-gz.hash !";
exit 1;
fi
cmp -s "$ssrc/hsums/$1-tbl.hash" "$ssrc/hsums/$2-tbl.hash";
if [ $? -ne 0 ]; then
echo "Byte mismatch with $1-tbl.hash !";
exit 1;
fi
cmp -s "$ssrc/hsums/$1.hash" "$ssrc/hsums/$2.hash";
if [ $? -ne 0 ]; then
echo "Byte mismatch with $1.hash !";
exit 1;
fi
cmp -s "$ssrc/parts/$1.part.gz" "$ssrc/parts/$2.part.gz";
if [ $? -ne 0 ]; then
echo "Byte mismatch with $1.part.gz !";
exit 1;
fi
cmp -s "$ssrc/tabls/$1.tbl" "$ssrc/tabls/$2.tbl";
if [ $? -ne 0 ]; then
echo "Byte mismatch with $1.tbl !";
exit 1;
fi
echo "Finished!";
exit 0;

25
backup-image/move.sh Executable file
View File

@ -0,0 +1,25 @@
#!/bin/bash
echo "Move Backup!";
if [ $# -eq 0 ]; then
echo "Usage: move.sh <Backup disk name> <Backup disk new name> [Storage disk root path]";
exit 2;
fi
ssrc="";
if [ -z $3 ]; then
ssrc="/mnt";
else
ssrc="$3";
fi
echo "Source Backup disk name: $1";
echo "Target Backup disk name: $2";
echo "Sync storage disk root path: $ssrc";
echo "Press Enter to Start...";
read;
echo "Moving...";
mv -f "$ssrc/hsums/$1-gz.hash" "$ssrc/hsums/$2-gz.hash";
mv -f "$ssrc/hsums/$1-tbl.hash" "$ssrc/hsums/$2-tbl.hash";
mv -f "$ssrc/hsums/$1.hash" "$ssrc/hsums/$2.hash";
mv -f "$ssrc/parts/$1.part.gz" "$ssrc/parts/$2.part.gz";
mv -f "$ssrc/tabls/$1.tbl" "$ssrc/tabls/$2.tbl";
echo "Finished!";
exit 0;

24
backup-image/remove.sh Executable file
View File

@ -0,0 +1,24 @@
#!/bin/bash
echo "Remove Backup!";
if [ $# -eq 0 ]; then
echo "Usage: remove.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 "Sync storage disk root path: $ssrc";
echo "Press Enter to Start...";
read;
echo "Deleting...";
rm -f "$ssrc/hsums/$1-gz.hash";
rm -f "$ssrc/hsums/$1-tbl.hash";
rm -f "$ssrc/hsums/$1.hash";
rm -f "$ssrc/parts/$1.part.gz";
rm -f "$ssrc/tabls/$1.tbl";
echo "Finished!";
exit 0;

31
backup-image/restore.sh Executable file
View File

@ -0,0 +1,31 @@
#!/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=/mnt/hsums/$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 -d "/dev/$2" < "/mnt/tabls/$1.tbl";
rm -rf /tmp/a;
echo "Finished!";
exit 0;

View File

@ -1,33 +1,39 @@
#!/bin/bash
echo "Sync Backup!";
if [ $# -eq 0 ]; then
echo "Usage: sync.sh <Backup disk name> <Sync target disk name> <Sync source disk name>";
echo "Usage: sync.sh <Backup disk name> <Sync target disk root path> [Sync source disk root path]";
exit 2;
fi
ssrc="";
if [ -z $3 ]; then
ssrc="/mnt";
else
ssrc="$3";
fi
echo "Source Backup disk name: $1";
echo "Sync target disk name: $2";
echo "Sync source disk name: $3";
echo "Sync target disk root path: $2";
echo "Sync source disk root path: $ssrc";
echo "Press Enter to Start...";
read;
mkdir -p /tmp/a;
echo "Syncing...";
cp -f "$3/hsums/$1-gz.hash" "$2/hsums/$1-gz.hash";
cp -f "$3/hsums/$1-tbl.hash" "$2/hsums/$1-tbl.hash";
cp -f "$3/hsums/$1.hash" "$2/hsums/$1.hash";
cp -f "$3/parts/$1.part.gz" "$2/parts/$1.part.gz";
cp -f "$3/tabls/$1.tbl" "$2/tabls/$1.tbl";
cp -f "$ssrc/hsums/$1-gz.hash" "$2/hsums/$1-gz.hash";
cp -f "$ssrc/hsums/$1-tbl.hash" "$2/hsums/$1-tbl.hash";
cp -f "$ssrc/hsums/$1.hash" "$2/hsums/$1.hash";
cp -f "$ssrc/parts/$1.part.gz" "$2/parts/$1.part.gz";
cp -f "$ssrc/tabls/$1.tbl" "$2/tabls/$1.tbl";
echo "Verifying...";
cmp -s "$3/hsums/$1-gz.hash" "$2/hsums/$1-gz.hash";
cmp -s "$ssrc/hsums/$1-gz.hash" "$2/hsums/$1-gz.hash";
if [ $? -ne 0 ]; then
echo "Hash mismatch with $1-gz.hash !";
exit 1;
fi
cmp -s "$3/hsums/$1-tbl.hash" "$2/hsums/$1-tbl.hash";
cmp -s "$ssrc/hsums/$1-tbl.hash" "$2/hsums/$1-tbl.hash";
if [ $? -ne 0 ]; then
echo "Hash mismatch with $1-tbl.hash !";
exit 1;
fi
cmp -s "$3/hsums/$1.hash" "$2/hsums/$1.hash";
cmp -s "$ssrc/hsums/$1.hash" "$2/hsums/$1.hash";
if [ $? -ne 0 ]; then
echo "Hash mismatch with $1.hash !";
exit 1;

38
backup-image/verify.sh Executable file
View File

@ -0,0 +1,38 @@
#!/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 "Sync storage disk root path: $ssrc";
echo "Press Enter to Start...";
read;
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") &
((sha512sum "$ssrc/tabls/$1.tbl" > "/tmp/a/$1.tbl.sum") && dd "if=/tmp/a/$1.tbl.sum" bs=128 count=1 "of=/mnt/hsums/$1-tbl.hash" && touch "/tmp/a/2.complete") &
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;