Backups That Check Themselves¶
Why¶
My backups had been running for years without a single complaint. restic with resticprofile on every host, a rest-server at home, a copy at my hoster. Green dashboard, no alerts.
Then I asked a simple question: "How much do I actually trust these backups?" - and took an honest look:
- One repository for all hosts, one password. Every host could read every other host's backup.
- No authentication on the rest-server. I tried it with a throwaway instance: a plain
DELETEon a snapshot and on a data file was accepted, no password needed. Every machine in my LAN, my mesh or a container network could have wiped the backups of all hosts. - Database dumps came from cron jobs inside the containers. If a dump failed, the old file just stayed where it was. restic backed it up again every night, and everything stayed green.
- A few services kept SQLite databases (Grafana, Jellyfin, CrowdSec, ARA). restic copied them while the service was writing.
- Nobody had ever restored anything. Not a file, not a database. I simply didn't know whether it would work.
None of this had ever caused a problem. That's exactly the kind of problem I don't want to find out about on the day I need a restore.
Starting Point¶
| what | before |
|---|---|
| repositories | one shared repository for all hosts, one password, a copy at the hoster |
| access | rest-server without authentication, deleting allowed |
| what is saved | one list of paths per host in the Ansible inventory, maintained by hand |
| databases | dumps by cron inside the containers, some services not dumped at all |
| monitoring | "the backup job ran" - nothing about the content |
| restore | never tested |
Target¶
- one repository per host, and no client can delete anything, not even its own snapshots
- the copy at the hoster is reachable from the backup host only
- every service says itself what has to be saved, and how it gets consistent before that
- a failed dump must be loud - but it must not stop the backup of everything else
- checks that read the data back, without disturbing the production hosts
- every gap in the backup is a decision with a reason, not something I forgot
How¶
One Repository per Host, Append-Only¶
The first part was the classic hardening, and it went quickly:
- One repository per host. I measured the deduplication across hosts first: 0.2 %. Not worth a shared repository.
- rest-server with
--append-onlyand--private-repos, every host with its own login. A client can write new snapshots to its own repository - and nothing else.forgetandprunerun locally on the backup host only. - The copy at the hoster gets a weekly
restic copyfrom the backup host, and Traefik only lets the backup host through. Thirty daily states at home, thirty daily plus 53 weekly at the hoster. - Passwords are derived from two secrets which live in Ansible Vault - and offline in my password manager, because without them no repository can be opened, including the one of GitLab.
The whole history moved over with restic copy (346 snapshots), the old shared repository stayed for a few days until every new repository
had passed a full check --read-data, then it was deleted.
The Service Describes Its Backup¶
The more interesting part was the question: who knows what has to be saved? Before, that was a list of paths per host in the inventory of my system Ansible repo. Move a service to another host, forget the list - and nobody notices.
But the service itself knows best. So every container project now declares its backup in one place, next to everything else it knows about itself:
# vars of the mariadb project
container_backup:
paths:
- "{{ mariadb_backup_dir }}"
dump: "{{ mariadb_backup_dir }}"
paths is what goes into the snapshot. dump says that the image brings two scripts: backup-dump writes a consistent dump right before the
backup, backup-verify checks such a dump read-only. A service without anything worth saving says false - with a comment why.
The deployment (my Ansible collection from the Hashistack exit) turns this into two things on the host:
- a small JSON descriptor under
/etc/opt/underverse/backup.d/: unit, image with its exact tag, paths, dump directory - for a dump, a oneshot systemd unit
<unit>-backup-dump.service, which just callspodman exec <unit> /usr/local/bin/backup-dump
The backup role on the host doesn't know a single service. It only knows the mechanism, the same on every host:
flowchart LR
T[backup.timer] --> B[backup@backup.service]
B -->|Wants, After| PT[backup-prepare.target]
PT --> D1[unit-a-backup-dump]
PT --> D2[unit-b-backup-dump]
PT --> H[backup-prepare-host<br/>canary, host hooks]
DS[descriptors<br/>/etc/opt/underverse/backup.d] -->|paths| R[restic backup]
B --> R
Wants, not Requires, and that was a deliberate decision: if one dump fails, its unit fails and alerts, but the backup still runs - with the
last good dump, because every dump goes through a temporary file first. With Requires, one broken database dump would cost the whole night
for the host.
The paths of the host system itself (/etc, /root, ...) stay in the inventory. A path below the service data directory is rejected there now,
and the deployment of a service with data but without container_backup fails. A gap in the backup is a decision now.
Moving a service to another host? The backup moves with it, because it's part of the service.
Two Scripts per Image¶
The same pair of scripts in every image, only the source and the list of databases differ:
| service | backup-dump |
backup-verify |
|---|---|---|
| MariaDB | mariadb-dump of all databases, compressed |
imports the dump into a throwaway mariadbd and compares the tables |
| GitLab | gitlab-backup create plus the config backup |
readable archive, complete database dump, same version as the image, secrets there |
| Grafana, Jellyfin, CrowdSec, ARA | sqlite3 .backup - consistent while the service writes |
PRAGMA integrity_check, tables present |
GitLab is the only image I don't build myself. There, both scripts are rendered from the project repo and mounted into the container at the same path - for the rest of the system, it looks exactly like the others.
No more cron jobs. A dump happens exactly when the backup needs it.
Three Checks¶
Backups that are never read are a hope, not a backup. So there are now three checks, each for a different part of the way back:
| check | where, when | what it proves |
|---|---|---|
| repository | both backup hosts, weekly | restic check --read-data-subset=n/4: every data file is read once in four weeks |
| canary | every host, daily after the backup | the host itself can restore and decrypt through rest-server, with its own login |
| dump | backup host, weekly | each dump in the newest snapshot works - checked with the image that wrote it |
The canary is a tiny file with a random value, written right before every backup. In the morning, each host restores it from its newest snapshot and compares it with the file on disk. Equal means: the last backup contains what was written right before it, and the way back works. It costs a few kilobytes and a second.
The dump check was the part I like most. The descriptor lies in /etc, so it's part of every snapshot: the snapshot describes itself.
Every week, the backup host restores the descriptors from the newest snapshot of each host, then only the dump directories, pulls exactly the
image named in the descriptor and runs
podman run --rm --read-only --network none <image> /usr/local/bin/backup-verify /restore
with the dump mounted read-only. MariaDB really imports the Nextcloud database (160 tables), the SQLite databases get their integrity check, GitLab's archive is checked against its version. No production host is touched - the backup host has all repositories anyway. And for GitLab's mounted scripts, the check simply reads the Quadlet unit from the same snapshot and mounts the script the same way.
Everything ends up in VictoriaMetrics, with alerts for failed and for stale checks, and a few more columns in the backup row of my Grafana dashboard.
What I Deliberately Don't Back Up¶
Not everything is worth it, and that's fine as long as it's a decision:
- VictoriaMetrics and VictoriaLogs (about 17 GB): nice curves, but they fill up again by themselves.
- GitLab's registry, packages, pages and artifacts: everything can be rebuilt from the repositories.
- The mail relay queue: restoring a queue from 3 a.m. would only send old mails again. The DKIM key comes from the vault anyway.
Pitfalls¶
sqlite3 Creates What It Can't Find¶
My first backup-dump for SQLite opened the database and wrote a copy. If the database was missing, sqlite3 happily created an empty one -
and its empty copy replaced the last good dump. Exit code 0. Now the source is opened read-only and must exist.
A Build Context That Never Forgets¶
After rolling out the new MariaDB image, the cron service I had just removed was still running in the container. The build copied the source files into a build directory - and never removed what was no longer in the source. This had been hiding there for years, long before the code became a collection. Now everything that isn't in the source anymore leaves the build context before each build.
Jinja Reads Bash Differently¶
${#array[@]} in a Jinja template is not the length of an array. {# is the start of a Jinja comment.
A systemd Target Stays Active¶
The backup pulls in backup-prepare.target, which pulls in the dump units. After the first night, the target was still active - and an active
target doesn't start its units again. StopWhenUnneeded=yes fixed it, a second test run showed it.
Clean Up Must Not Throw Away Someone Else's Data¶
The descriptors first lived in /etc/restic/. But the backup role removes that whole directory when backups are switched off on a host. Switch it
back on, and the descriptors would have been missing until every project was deployed again - silently. They belong to the deployment, so they
live outside the backup role now.
Some Findings on the Way¶
- The GitLab registry cleanup in my cron setup had never run - the switch for it was never set. Not needed anyway: with the registry metadata database, GitLab cleans up online by itself.
restic snapshots latestexits with an error on an empty repository.--latest 1returns an empty list.- resticprofile turns restic's exit code 10 ("repository does not exist") into a 1.
- The path I had backed up as "the mail relay data" for years was the Postfix queue. The thing I thought I was saving was somewhere else - and already in the backup.
Effort and Duration¶
| date | milestone |
|---|---|
| 20.11.2026 | the question, the analysis, the test with DELETE |
| 21.11.2026 | one repository per host, append-only, history copied |
| 22.11.2026 | old repository deleted, the service describes its backup, all dumps converted |
| 23.11.2026 | first night: all dumps, all backups, all canaries green; first dump check: 6 of 6 |
Four days. Again together with Claude Code, the same way as in the Hashistack exit: it read, measured, tested on a throwaway VM and wrote the archive; decisions, commits, builds and production rollouts stayed with me. A good part of the design came from me saying "that's not generic enough" - and from it saying "that path is the mail queue, not the DKIM key".
Final State¶
| what | after |
|---|---|
| repositories | one per host, append-only, own login; a copy at the hoster, reachable from the backup host only |
| what is saved | declared by each service (container_backup), checked at deployment; the inventory only lists system paths |
| databases | dumped right before the backup by a script in the image; a failed dump alerts, the backup still runs |
| checks | repository data weekly, the way back daily, every dump weekly with the image that wrote it |
| decisions | everything not backed up says so, with a reason |
What's still open: a real restore drill per service - GitLab really coming back with its secrets, Nextcloud with its files and the database. The steps are written down, but not yet practiced. That's the next thing.
Conclusion¶
The old setup wasn't broken. It just never had to prove anything. Now every night proves something, and every week a bit more.
And the part I didn't expect: once the service describes its own backup, the question "is this backed up?" is answered in the same file where everything else about the service is. That alone was worth it.