Why Link to heading
To ensure you can successfully restore a file from a tar
backup. A sha256sum
only checks the integrity of the created archive, not it’s restorability.
Prerequisites Link to heading
- Create a playground:
mkdir archive-test
cd archive-test
- Create some content:
mkdir content
echo content1 >> content/file1
echo content2 >> content/file2
echo content3 >> content/file3
- Back up your content:
tar -cf backup1.tar content
Canary Link to heading
- Generate a random id:
export CANARY_ID=$(tr -dc "a-zA-Z0-9" < /dev/urandom | head -c 32)
- Save that id to a file:
echo $CANARY_ID > canary
- Add it to your archive:
tar -rf backup1.tar canary
- Rename your archive to contain the id:
mv backup1.tar backup1."$CANARY_ID".tar
- Remove the unarchived canary file:
rm -f canary
- Optionally compress/encrypt/checksum the archive with
gzip
,gpg
, andsha256sum
.
Restore Link to heading
- Extract the canary id:
export RESTORE_ID=$(ls backup1.$CANARY_ID.tar | cut -d '.' -f 2)
- Extract the canary file:
tar -xf backup1."$CANARY_ID".tar canary
- Compare the two values:
[ "$CANARY_ID" == "$RESTORE_ID" ] && echo "Match!" || echo "Fail!" && false
Cleanup Link to heading
Don’t forget to remove your test files after playing with this:
cd ..
rm -rf archive-test