Add backup sync between mounts support.

Make sure a hash is saved for the partition table file.
This commit is contained in:
Captain ALM 2024-08-04 16:08:58 +01:00
parent c85918a065
commit 4dc2953c32
Signed by: alfred
GPG Key ID: 4E4ADD02609997B1
2 changed files with 51 additions and 1 deletions

View File

@ -26,8 +26,9 @@ fi
cp -f "/tmp/a/$2-gz.hash" "/mnt/hsums/$2-gz.hash"; cp -f "/tmp/a/$2-gz.hash" "/mnt/hsums/$2-gz.hash";
cp -f "/tmp/a/$2.hash" "/mnt/hsums/$2.hash"; cp -f "/tmp/a/$2.hash" "/mnt/hsums/$2.hash";
echo; echo;
rm -rf /tmp/a;
echo "Backing up partition table..."; echo "Backing up partition table...";
sfdisk -d "/dev/$1" > "/mnt/tabls/$2.tbl"; sfdisk -d "/dev/$1" > "/mnt/tabls/$2.tbl";
(sha512sum "/mnt/tabls/$2.tbl" > "/tmp/a/$2.tbl.sum") && dd "if=/tmp/a/$2.tbl.sum" bs=128 count=1 "of=/mnt/hsums/$2-tbl.hash";
rm -rf /tmp/a;
echo "Finished!"; echo "Finished!";
exit 0; exit 0;

49
backup-image/sync.sh Executable file
View File

@ -0,0 +1,49 @@
#!/bin/bash
echo "Sync Backup!";
if [ $# -eq 0 ]; then
echo "Usage: sync.sh <Backup disk name> <Sync target disk name>";
exit 2;
fi
echo "Source Backup disk name: $1";
echo "Sync target disk name: $2";
echo "Press Enter to Start...";
read;
mkdir -p /tmp/a;
echo "Syncing...";
cp -f "/mnt/hsums/$1-gz.hash" "$2/hsums/$1-gz.hash";
cp -f "/mnt/hsums/$1-tbl.hash" "$2/hsums/$1-tbl.hash";
cp -f "/mnt/hsums/$1.hash" "$2/hsums/$1.hash";
cp -f "/mnt/parts/$1.part.gz" "$2/parts/$1.part.gz";
cp -f "/mnt/tabls/$1.tbl" "$2/tabls/$1.tbl";
echo "Verifying...";
cmp -s "/mnt/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 "/mnt/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 "/mnt/hsums/$1.hash" "$2/hsums/$1.hash";
if [ $? -ne 0 ]; then
echo "Hash mismatch with $1.hash !";
exit 1;
fi
((sha512sum "$2/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 "$2/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" && touch "/tmp/a/2.complete") &
until [ -f "/tmp/a/1.complete" ] && [ -f "/tmp/a/2.complete" ]; do sleep 0.1; done;
cmp -s "/tmp/a/$1-gz.hash" "$2/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" "$2/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;