My backups were fine. My restores weren't.
When I rebuilt the box after the SSD failure last year, I restored /etc and a few scripts from backup, and that went fine. But it bothered me afterward that I had never restored anything from the data backups, because I'd never needed to. Every night the snapshot ran, every Sunday the digest said 7 runs and 0 failed, and I had no evidence at all that the files in those snapshots were the files I'd want back.
So in December I did a restore drill. It found two problems, one of them fourteen months old.
The setup
Nightly snapshots go to an 8 TB USB disk plugged into the box. Each one is a complete directory tree, with unchanged files hard-linked to the previous night's copy, so thirty of them take up only a little more room than one:
today=$(date +%F)
rsync -aHR --link-dest=/mnt/backup/latest \
--exclude-from=/etc/backup-excludes \
/home /srv /etc "/mnt/backup/$today/"
ln -sfn "$today" /mnt/backup/latest
A second disk gets a full copy on the first of each month and lives in a drawer at my sister's house across town, in case the closet floods or worse.
The drill
It happens on the first Saturday of the month and has two parts.
The random part picks 25 files from the latest snapshot and compares each one, byte for byte, with the live copy. Files I've changed since the snapshot was taken get skipped:
#!/bin/bash
snap=$(readlink -f /mnt/backup/latest)
find "$snap" -type f -size -200M | shuf -n 25 |
while read -r f; do
live=${f#"$snap"}
if [ ! "$live" -ot "$snap" ]; then echo "skip $live"; continue; fi
if cmp -s "$f" "$live"; then echo "ok $live"; else echo "DIFF $live"; fi
done
The deliberate part is me choosing one thing and restoring it properly, into a scratch directory, the way I would if I'd really lost it: a photo album, last year's tax folder, the pantry database. Then I open what came back. A file that compares equal but won't open is still a lost file.
What went wrong the first time
A folder had never been backed up. The excludes file had a line, build/, meant to skip compiler output in my code checkouts. A pattern like that matches a directory of that name anywhere in the tree, and one of them was ~/documents/house/build/, where I keep the scanned permits and invoices from the porch work in 2023. Since the day I made that folder, every snapshot had skipped it without a word.
The random part of the drill could never have caught this, since it can't pick a file that isn't there. Restoring the whole house folder did, because the subfolder was simply missing from the restored copy. The fix was to anchor the pattern to where the code actually lives:
/home/wendell/src/**/build/
I also added a crude check to the drill: list every directory under /home and /srv, do the same in the snapshot, and diff the two lists. Anything excluded by accident shows up as a missing line. It takes about a minute, and it would have caught this the first night.
The pantry database came back damaged. I keep a small SQLite database of what's in the pantry and the freezer. The restored copy opened, and then failed PRAGMA integrity_check with a handful of errors. The snapshot and the pantry app's own nightly job both started at 02:30, so rsync was sometimes copying the file while it was being written. Some nights that's harmless and some nights it isn't, and nothing outside the file tells you which.
Now the snapshot script starts by asking SQLite for a consistent copy, and the excludes file skips the live database in favor of that copy:
sqlite3 /srv/pantry/pantry.db ".backup /srv/dumps/pantry.db"
I moved the pantry job to 04:00 as well, for good measure.
Was it worth it?
The first drill took most of an evening, almost all of it spent on those two problems. The January one took twelve minutes and found nothing, which is the result I want every month and the one I've stopped taking for granted.
What I keep coming back to is that every signal I had before December was about the backup job, not the backup. Exit code 0 means rsync did what I asked. It doesn't mean I asked for the right thing.