if your backup runs as a service, systemctl status will happily say active (running) while nothing is being backed up. I've seen it with Litestream, and the fix that stuck wasn't a better check on the process. it was checking the output instead.
this is what I run on a handful of small VPS. what the failure looks like, the ~50 line guard that catches it, and the restore drills that prove the backups are real, with the timings from those drills.
TL;DR
- a replicator can stay
activewhile every sync fails. watch the replica, not the process. - the guard runs every 2 min, checks two signals (a bind mount pointing at a deleted directory, and Litestream saying "database behind replica") and re-seeds to a fresh replica path. it never reconciles the old one.
- alerts that only fire on a state change go quiet after the first push. mine repeat every 6 h until the check is green.
- timed drills: about 3 min from backup to
/health200 on a prepared host, about 10 s of data loss through Litestream, every table identical to live.
the failure mode
SQLite app, Litestream streaming the database to object storage every ~10 s, data in a bind mount.
the app's updater re-extracted its data volume during an update. the bind mount kept pointing at the old directory, which didn't exist anymore. from there:
- the app kept running on the new files
- Litestream kept running too, against a path that was gone
- every 5 min it logged a sync error
- systemd said
activethe whole time
process check green, replica frozen. a DR drill caught it by comparing row counts per table, one table had 67 rows in the replica and 91 in the daily archive. that's the kind of thing a process check can never tell you.
the guard
two signals, both cheap.
-
findmnt -no SOURCEon the bind. if the source containsdeleted, the mount is stale. - the last 5 min of Litestream's journal. if it says
detected database behind replica, stop.
the second one matters more than it looks. restarting Litestream against a replica that's ahead of your local database makes it try to reconcile, and I don't want a timer deciding which side wins. so the rule is never reconcile. start a fresh replica path and leave the old one frozen as an extra copy.
simplified, with names changed:
#!/bin/sh set -u BIND=/srv/app-sqlite CONF=/etc/litestream.yml reason="" case "$(findmnt -no SOURCE "$BIND")" in *deleted*) reason="bind points at a deleted directory" ;; esac if [ -z "$reason" ] && journalctl -u litestream --since -5min -o cat \ | grep -q "detected database behind replica"; then reason="litestream reported database behind replica" fi [ -z "$reason" ] && exit 0 new="app/app-$(date -u +%Y%m%dT%H%M)" [ "${GUARD_DRY:-0}" = 1 ] && { echo "DRY: $reason, would re-seed to $new"; exit 0; } alert "$reason, re-seeding to $new" systemctl stop litestream systemctl restart 'srv-app\x2dsqlite.mount' case "$(findmnt -no SOURCE "$BIND")" in *deleted*) alert "remount did not fix $BIND, litestream left stopped"; exit 1 ;; esac [ -s "$BIND/app.sqlite" ] || { alert "no database after remount, litestream left stopped"; exit 1; } mv "$BIND/.app.sqlite-litestream" "$BIND-stale-shadow-$(date -u +%s)" # point the replica at $new in $CONF (old path stays untouched) systemctl start litestream alert "re-seeded to $new" it runs from a systemd timer every 2 min. GUARD_DRY=1 prints the decision and changes nothing, that's how it got tested before it was allowed to touch anything.
the part I like most is what it refuses to do. remount didn't help, or the database file is missing or empty? it leaves Litestream stopped and shouts. a stopped replicator with a loud alert beats one that happily replicates the wrong file.
alerts that repeat
alert on change sounds clean. one push when a check goes bad, one when it recovers. but if that one push lands while you're asleep, or the phone is on silent, nothing else ever comes.
so every check in my monitor repeats STILL DOWN every 6 h while it stays bad. mesh, backups, every public site. it's only noisy while something is actually broken, which is exactly when it should be.
restore drills, timed
the guard covers one failure mode. a drill is what tells you the backup is actually usable.
drill 1, a SQLite app, restored on a prepared host (WireGuard, reverse proxy and certs already there):
| measure | value |
|---|---|
| download the encrypted archive | 63 s |
| decrypt and extract | 36 s |
| assemble data dir | 1 s |
| pull the container image | 56 s |
boot to /health 200 | 4 s |
| RTO total | about 3 min |
| RPO through Litestream | about 10 s, identical to live on all 61 tables |
| RPO through the daily archive | up to 24 h |
| integrity | quick_check ok on archive, replica and live |
drill 2, another app, server treated as gone: database and config pulled from the encrypted backup, app running on another server in about 2 min with identical data. 4 s for the data, 107 s to copy the container image, under 1 s to start. the image is the part people forget to back up.
things the drills turned up, which is their whole job:
- container images weren't in any backup. the data comes back in seconds, but if the image only lives on the dead server, that's your real RTO. now it's kept on a second box.
- streaming the encrypted archive straight from an API broke mid-transfer once, and the decryptor rejected the truncated chunk. now it's download to a file, check size and hash, then decrypt.
- the restored copy boots with
--network none. a restore should never start talking to real users or bots before you decide it's the real one.
rules I'd copy
- check the output's age, not the process state.
- never let automation reconcile a replica that's ahead. new path, old one stays frozen.
- dry-run mode for anything that touches backups on its own.
- alerts repeat until green.
- one copy gets pulled by another box with a read-only key (
rrsync -ro), so whoever gets the server can't delete every backup. alert when that copy is older than 36 h. - time the drill. "we have backups" means nothing until you know how long the restore takes.
next on my list is timing a restore onto a completely bare host, WireGuard and proxy included. the 3 min above assumes those are already there.
how do you check yours, process status or replica age? and when did you last time a restore end to end? 😅



