From 9e0f2f180815c120bc08e2957b60574099764cea Mon Sep 17 00:00:00 2001 From: Captain ALM Date: Sun, 23 Feb 2025 15:01:55 +0000 Subject: [PATCH] Switch out tmp folder to use one from uuidgen. --- backup-image/backup.sh | 27 ++++++++++++++------------- backup-image/restore.sh | 13 +++++++------ backup-image/sync-btime.sh | 13 +++++++------ backup-image/verify.sh | 23 ++++++++++++----------- 4 files changed, 40 insertions(+), 36 deletions(-) diff --git a/backup-image/backup.sh b/backup-image/backup.sh index f6cf112..12a43ef 100755 --- a/backup-image/backup.sh +++ b/backup-image/backup.sh @@ -8,30 +8,31 @@ echo "Source Disk: /dev/$1"; echo "Destination Name: $2"; echo "Press Enter to Start..."; read; -mkdir -p /tmp/a; +uuidTmp="/tmp/a-$(uuidgen)"; +mkdir -p $uuidTmp; dd "if=/dev/$1" status=progress conv=sync,noerror | gzip -6 -c > "/mnt/parts/$2.part.gz"; echo -n "$(date +%s)" > "/mnt/times/$2.time; 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") & -((sha512sum "/mnt/times/$2.time" > "/tmp/a/$2.time.sum") && dd "if=/tmp/a/$2.time.sum" bs=128 count=1 "of=/tmp/a/$2-time.hash" && touch "/tmp/a/4.complete") & -until [ -f "/tmp/a/1.complete" ] && [ -f "/tmp/a/2.complete" ] && [ -f "/tmp/a/3.complete" ] && [ -f "/tmp/a/4.complete" ]; do sleep 0.1; done; +((sha512sum "/dev/$1" > "$uuidTmp/$1.sum") && dd "if=$uuidTmp/$1.sum" bs=128 count=1 "of=$uuidTmp/$1.hash" && touch "$uuidTmp/1.complete") & +((sha512sum "/mnt/parts/$2.part.gz" > "$uuidTmp/$2.part.gz.sum") && dd "if=$uuidTmp/$2.part.gz.sum" bs=128 count=1 "of=$uuidTmp/$2-gz.hash" && touch "$uuidTmp/2.complete") & +((gunzip -c "/mnt/parts/$2.part.gz" | sha512sum > "$uuidTmp/$2.part.sum") && dd "if=$uuidTmp/$2.part.sum" bs=128 count=1 "of=$uuidTmp/$2.hash" && touch "$uuidTmp/3.complete") & +((sha512sum "/mnt/times/$2.time" > "$uuidTmp/$2.time.sum") && dd "if=$uuidTmp/$2.time.sum" bs=128 count=1 "of=$uuidTmp/$2-time.hash" && touch "$uuidTmp/4.complete") & +until [ -f "$uuidTmp/1.complete" ] && [ -f "$uuidTmp/2.complete" ] && [ -f "$uuidTmp/3.complete" ] && [ -f "$uuidTmp/4.complete" ]; do sleep 0.1; done; echo "Hashes:"; -cat /tmp/a/*.sum; +cat $uuidTmp/*.sum; echo; -cmp -s "/tmp/a/$1.hash" "/tmp/a/$2.hash"; +cmp -s "$uuidTmp/$1.hash" "$uuidTmp/$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"; -cp -f "/tmp/a/$2-time.hash" "/mnt/hsums/$2-time.hash"; +cp -f "$uuidTmp/$2-gz.hash" "/mnt/hsums/$2-gz.hash"; +cp -f "$uuidTmp/$2.hash" "/mnt/hsums/$2.hash"; +cp -f "$uuidTmp/$2-time.hash" "/mnt/hsums/$2-time.hash"; echo; echo "Backing up partition table..."; 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; +(sha512sum "/mnt/tabls/$2.tbl" > "$uuidTmp/$2.tbl.sum") && dd "if=$uuidTmp/$2.tbl.sum" bs=128 count=1 "of=/mnt/hsums/$2-tbl.hash"; +rm -rf $uuidTmp; echo "Finished!"; exit 0; diff --git a/backup-image/restore.sh b/backup-image/restore.sh index 0dd8176..f048077 100755 --- a/backup-image/restore.sh +++ b/backup-image/restore.sh @@ -8,17 +8,18 @@ echo "Destination Disk: /dev/$2"; echo "Source Backup Name: $1"; echo "Press Enter to Start..."; read; -mkdir -p /tmp/a; +uuidTmp="/tmp/a-$(uuidgen)"; +mkdir -p $uuidTmp; 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"; +(sha512sum "/dev/$2" > "$uuidTmp/$2.sum") && dd "if=$uuidTmp/$2.sum" bs=128 count=1 "of=$uuidTmp/$2.hash"; +cmp -s "$uuidTmp/$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"; +(sha512sum "/mnt/tabls/$1.tbl" > "$uuidTmp/$1.tbl.sum") && dd "if=$uuidTmp/$1.tbl.sum" bs=128 count=1 "of=$uuidTmp/$1-tbl.hash"; +cmp -s "$uuidTmp/$1-tbl.hash" "/mnt/hsums/$1-tbl.hash"; if [ $? -ne 0 ]; then echo "Partition hashes do not match!"; exit 1; @@ -26,6 +27,6 @@ fi echo; echo "Restoring up partition table..."; sfdisk -d "/dev/$2" < "/mnt/tabls/$1.tbl"; -rm -rf /tmp/a; +rm -rf $uuidTmp; echo "Finished!"; exit 0; diff --git a/backup-image/sync-btime.sh b/backup-image/sync-btime.sh index 6a553dc..21a94d7 100755 --- a/backup-image/sync-btime.sh +++ b/backup-image/sync-btime.sh @@ -27,7 +27,8 @@ if [[ "$5" != "ikwid" ]]; then echo "Press Enter to Start..."; read; fi -mkdir -p /tmp/a; +uuidTmp="/tmp/a-$(uuidgen)"; +mkdir -p $uuidTmp; echo "Syncing..."; cmp -s "$ssrc/hsums/$2-tbl.hash" "$3/hsums/$2-tbl.hash" sTbl=$?; @@ -83,8 +84,8 @@ if [ $sTbl -ne 0 ]; then echo "Hash mismatch with $2-tbl.hash !"; exit 1; fi - (sha512sum "$3/tabls/$2.tbl" > "/tmp/a/$2.tbl.sum") && dd "if=/tmp/a/$2.tbl.sum" bs=128 count=1 "of=/tmp/a/$2-tbl.hash"; - cmp -s "/tmp/a/$2-tbl.hash" "$3/hsums/$2-tbl.hash"; + (sha512sum "$3/tabls/$2.tbl" > "$uuidTmp/$2.tbl.sum") && dd "if=$uuidTmp/$2.tbl.sum" bs=128 count=1 "of=$uuidTmp/$2-tbl.hash"; + cmp -s "$uuidTmp/$2-tbl.hash" "$3/hsums/$2-tbl.hash"; if [ $? -ne 0 ]; then echo "Hash mismatch with $2.tbl !"; exit 1; @@ -102,8 +103,8 @@ if [ $sPart -ne 0 ]; then echo "Hash mismatch with $2.hash !"; exit 1; fi - (sha512sum "$3/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"; - cmp -s "/tmp/a/$2-gz.hash" "$3/hsums/$2-gz.hash"; + (sha512sum "$3/parts/$2.part.gz" > "$uuidTmp/$2.part.gz.sum") && dd "if=$uuidTmp/$2.part.gz.sum" bs=128 count=1 "of=$uuidTmp/$2-gz.hash"; + cmp -s "$uuidTmp/$2-gz.hash" "$3/hsums/$2-gz.hash"; if [ $? -ne 0 ]; then echo "Hash mismatch with $2.part.gz !"; exit 1; @@ -122,6 +123,6 @@ if [ $hT -eq 1 ]; then exit 1; fi fi -rm -rf /tmp/a; +rm -rf $uuidTmp; echo "Finished!"; exit 0; diff --git a/backup-image/verify.sh b/backup-image/verify.sh index 517bd96..a553255 100755 --- a/backup-image/verify.sh +++ b/backup-image/verify.sh @@ -16,37 +16,38 @@ if [[ "$3" != "ikwid" ]]; then echo "Press Enter to Start..."; read; fi -mkdir -p /tmp/a; +uuidTmp="/tmp/a-$(uuidgen)"; +mkdir -p $uuidTmp; 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=/tmp/a/$1-tbl.hash" && touch "/tmp/a/2.complete") & +((sha512sum "$ssrc/parts/$1.part.gz" > "$uuidTmp/$1.part.gz.sum") && dd "if=$uuidTmp/$1.part.gz.sum" bs=128 count=1 "of=$uuidTmp/$1-gz.hash" && touch "$uuidTmp/1.complete") & +((sha512sum "$ssrc/tabls/$1.tbl" > "$uuidTmp/$1.tbl.sum") && dd "if=$uuidTmp/$1.tbl.sum" bs=128 count=1 "of=$uuidTmp/$1-tbl.hash" && touch "$uuidTmp/2.complete") & if [ -f "$ssrc/times/$1.time" ]; then - ((sha512sum "$ssrc/times/$1.time" > "/tmp/a/$1.time.sum") && dd "if=/tmp/a/$1.time.sum" bs=128 count=1 "of=/tmp/a/$1-time.hash" && touch "/tmp/a/3.complete") & + ((sha512sum "$ssrc/times/$1.time" > "$uuidTmp/$1.time.sum") && dd "if=$uuidTmp/$1.time.sum" bs=128 count=1 "of=$uuidTmp/$1-time.hash" && touch "$uuidTmp/3.complete") & else - touch "/tmp/a/3.complete"; + touch "$uuidTmp/3.complete"; fi -until [ -f "/tmp/a/1.complete" ] && [ -f "/tmp/a/2.complete" ] && [ -f "/tmp/a/3.complete" ]; do sleep 0.1; done; +until [ -f "$uuidTmp/1.complete" ] && [ -f "$uuidTmp/2.complete" ] && [ -f "$uuidTmp/3.complete" ]; do sleep 0.1; done; echo "Hashes:"; -cat /tmp/a/*.sum; +cat $uuidTmp/*.sum; echo; -cmp -s "/tmp/a/$1-gz.hash" "$ssrc/hsums/$1-gz.hash"; +cmp -s "$uuidTmp/$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"; +cmp -s "$uuidTmp/$1-tbl.hash" "$ssrc/hsums/$1-tbl.hash"; if [ $? -ne 0 ]; then echo "Hash mismatch with $1.tbl !"; exit 1; fi if [ -f "$ssrc/times/$1.time" ]; then - cmp -s "/tmp/a/$1-time.hash" "$ssrc/hsums/$1-time.hash"; + cmp -s "$uuidTmp/$1-time.hash" "$ssrc/hsums/$1-time.hash"; if [ $? -ne 0 ]; then echo "Hash mismatch with $1.time !"; exit 1; fi fi -rm -rf /tmp/a; +rm -rf $uuidTmp; echo "Finished!"; exit 0;