iac/RESTORE.md
Sergei Poljanski 6d9122eeff
Some checks failed
nixos / nixos (push) Has been cancelled
main: the current setup only
Both servers run NixOS. The Ansible code and the move itself leave main
for their own branches: `ansible` is the Debian/Ansible setup as it was
before the migration, `migration` keeps the plan and record, the data
scripts and everything else the move needed.

README and RESTORE describe the setup as it is now: NixOS, Podman,
sops, OpenTofu, the backup paths and hooks of the new layout. The
README carries the TODO list that MIGRATION.md had. The Forgejo
sanitising script stays, under hosts/rehearsal, with the rules for
rehearsing on restored production data in the NixOS README. Renovate
no longer looks at Ansible files.

Assisted-by: Claude:opus-5-5
2026-11-17 10:08:40 +04:00

88 lines
3.9 KiB
Markdown

# Restoring from backups
Each host backs itself up nightly with restic (ops 03:30, services 04:15
UTC) into two independent repositories:
| Name | Repository |
|------|------------|
| `hel1` | `s3:https://hel1.your-objectstorage.com/asxpio-backups-main/restic/<host>` |
| `fsn1` | `s3:https://fsn1.your-objectstorage.com/asxpio-backups-repl/restic/<host>` |
What a snapshot holds is declared next to each service (`asxpio.backup`
in `nixos/`): paths, and hooks that put consistent copies of databases
into `/var/backups/restic-stage` just before the run.
| Host | Paths | In `/var/backups/restic-stage` |
|------|-------|--------------------------------|
| asxpio-ops | `/etc/ssh`, `/opt` (app stacks), `/var/lib/forgejo`, `/var/lib/garage` (after a metadata snapshot), `/var/lib/traefik`, `/var/lib/grafana` | `pg_dumpall.sql`, `asxpio.dump` (`pg_dump -Fc`), `forgejo.db` |
| asxpio-services | `/etc/ssh`, `/opt` (XMPP state), `/var/lib/minecraft`, `/var/lib/SillyTavern`, the Podman volumes `xmpp_database` and `xmpp_tackygram` | `ejabberd.sqlite`; Mnesia as `nightly.backup` inside `xmpp_database` |
Not in the backup: Postgres' data directory (restore from the dump),
Prometheus and Loki's local data, and what Minecraft downloads again.
Three secrets are needed: the Object Storage keys (`s3/access_key`,
`s3/secret_key`) and the restic password (`restic/password`), all in
`nixos/secrets/<host>.yaml`. **Without the password nothing can be read.**
## One file or one service, on a running host
```sh
restic-backup hel1 snapshots
restic-backup hel1 ls latest /var/lib/minecraft/world
restic-backup fsn1 restore latest --target /tmp/r --include /opt/xmpp
```
Restore beside the live data, compare, then stop the service and move
the files into place.
## A whole host
Build a fresh host first (`nixos/README.md`). Services that own data do
not start until `/var/lib/.data-in-place` exists, so nothing creates
empty state where the restore lands.
```sh
export AWS_ACCESS_KEY_ID=... AWS_SECRET_ACCESS_KEY=... RESTIC_PASSWORD=...
export RESTIC_REPOSITORY=s3:https://hel1.your-objectstorage.com/asxpio-backups-main/restic/asxpio-ops
restic snapshots --host asxpio-ops
restic restore latest --host asxpio-ops --target /
```
Then, on ops:
1. `touch /var/lib/.data-in-place; systemctl start postgresql`
2. `runuser -u postgres -- psql -q postgres < /var/backups/restic-stage/pg_dumpall.sql`
(one error, `role "postgres" already exists`, is expected), then
`systemctl restart postgres-roles` to set the passwords from sops.
3. Replace Forgejo's database with the staged copy:
`cp /var/backups/restic-stage/forgejo.db /var/lib/forgejo/data/forgejo.db`,
`chown git:git` it, then `forgejo-admin regenerate keys`.
4. Reboot. Everything starts, the app containers through podman-restart.
On services: the XMPP volumes come back with the restore; replace
`ejabberd.sqlite` in `xmpp_database` with the staged copy, and if Mnesia
does not come up clean, `podman exec xmpp-ejabberd ejabberdctl restore
/opt/ejabberd/database/nightly.backup`. Then `touch
/var/lib/.data-in-place` and reboot.
Check: the sites answer (Grafana → Probes), a git clone over SSH, an XMPP
login, the Minecraft world, the next nightly backup.
## Backups from the Debian era
Snapshots taken before 2026-11-17 hold the Debian/Docker layout
(`/opt/forgejo`, Docker volumes). Restore one to a side directory and
let the migration scripts on branch `migration` move it into place:
```sh
git show migration:nixos/migration/ops-data.sh > /tmp/ops-data.sh # or services-data.sh
restic restore <snapshot> --target /restore
bash /tmp/ops-data.sh /restore
```
## Keeping this true
After a change to what is backed up, and at least twice a year, restore
the latest snapshot of each host onto a rehearsal server (`nixos/README.md`)
and walk through this page. Last walk-through: 2026-11-17, both hosts
(the ops runbook on a fresh server with that night's backup).