Created
October 27, 2018 23:29
-
-
Save lgommans/8b12aad3065e47bdaa526a2dadbada82 to your computer and use it in GitHub Desktop.
Test backup solution for bit-rot detection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
### Run this script in an otherwise empty directory. It currently tests rsync and restic on btrfs. ### | |
### Tested on Debian Buster with restic 0.9.2, rsync 3.1.2, and btrfs-progs 4.17. ### | |
if [ "x$(sudo whoami)" != "xroot" ]; then | |
echo "No root, cannot use (u)mount." | |
exit 1 | |
fi | |
if [ -d mnt ]; then | |
echo "Directory ./mnt/ exists. Please run me in an empty directory."; | |
exit 2 | |
fi | |
export RESTIC_PASSWORD_FILE=resticpassword | |
set -x | |
rm -r backuprestic backuprsync | |
mkdir backuprestic backuprsync mnt | |
echo -n oopsie > resticpassword | |
restic -r backuprestic init | |
dd if=/dev/zero of=fs.btrfs bs=4096 count=$((1024*1024*109/4096)) | |
mkfs.btrfs fs.btrfs | |
sudo mount fs.btrfs mnt | |
sudo chmod 0777 mnt | |
yes "Hello World!" | head -1000 | tr -d \\n > mnt/testfile | |
rsync --delete -a mnt/ backuprsync/ | |
restic -r backuprestic backup mnt | |
sudo umount mnt | |
hd fs.btrfs > /tmp/a | |
strings -t d fs.btrfs | grep Hello | awk '{print $1}' | while read offset; do | |
echo -n Y | dd of=fs.btrfs count=1 seek=$offset bs=1 conv=notrunc 2>/dev/null | |
done | |
hd fs.btrfs > /tmp/b | |
git diff --color=always /tmp/{a,b} | grep -e + -e '-' | |
sudo mount fs.btrfs mnt | |
touch mnt/testfile | |
rsync --delete -a mnt/ backuprsync/ | |
echo "Rsync exit status: $?" | |
restic -v -r backuprestic backup mnt | |
echo "Restic exit status: $?" | |
sudo umount mnt | |
set +x | |
echo "Expected result: testfile" | |
echo "Actual result for backuprsync: $(ls backuprsync | grep testfile)" | |
echo "Actual result for backuprestic: $(restic -r backuprestic ls latest | grep testfile)" | |
rmdir mnt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment