Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Test backup solution for bit-rot detection
#!/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
if [ -d mnt ]; then
echo "Directory ./mnt/ exists. Please run me in an empty directory.";
exit 2
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
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
You can’t perform that action at this time.