learn.halkyon.eu backs up its database every hour, encrypted, to a Hetzner Storage Box:
`backup.sh`, started by the systemd timer in `backup/`. The database is all there is to
back up: people's files are in it too (Serverpod's database cloud storage). The other
state of the instance is `deploy/.env`, whose secrets are kept in a password manager,
and Caddy's certificates, which it fetches again.
| | |
|---|---|
| When | every hour, on the hour; a run missed while the server was off happens when it is back |
| What | `pg_dump` of the whole database, stored by [restic](https://restic.net) (encrypted, deduplicated, compressed) |
| Kept | 24 hourly, 7 daily, 4 weekly and 3 monthly snapshots; a deleted account is gone from every backup within about 3 months |
| Where | a sub-account of the Storage Box (SFTP), used for nothing else |
| Protected by | the box's automatic snapshots, daily, which only Hetzner's Console can remove: a taken-over server can delete what restic wrote, but not those |
| Checked | every night at 03:00: forgotten snapshots pruned, the repository's structure read; on Sundays also a random tenth of the data |
| Failures | in the journal only: `systemctl status halkyon-backup`, `journalctl -u halkyon-backup` |
The newest dump also stays on the server, as `~deploy/backups/latest.dump`.
**Without the restic password, the backups can't be read by anyone, you included.** Keep
it, with the box's login, somewhere other than the server.
## What a restore loses
A restore takes the instance back to the time of the backup, up to an hour ago. Devices
then sync with a server that has forgotten their last hour:
- **Someone who used the instance before the backup** loses nothing: their devices still
have what the server lost, and send it again.
- **Someone who started after the backup** is unknown to the server. At the next start,
their app finds its session gone, starts a new anonymous account and deletes the old
one's data from the device, the only copy left. The same happens to a device that
signed in after the backup, though a GitHub account can be signed into again.
- **An account deleted after the backup** comes back. Delete it again if you know which
one it was.
## Setting it up
Once, in this order. The commands name who runs them, and where.