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
This commit is contained in:
parent
168fd2ecb9
commit
6d9122eeff
1 changed files with 135 additions and 34955 deletions
131
RESTORE.md
131
RESTORE.md
|
|
@ -8,120 +8,81 @@ UTC) into two independent repositories:
|
|||
| `hel1` | `s3:https://hel1.your-objectstorage.com/asxpio-backups-main/restic/<host>` |
|
||||
| `fsn1` | `s3:https://fsn1.your-objectstorage.com/asxpio-backups-repl/restic/<host>` |
|
||||
|
||||
A snapshot holds `/etc`, `/opt`, the listed container volumes and
|
||||
`/var/backups/restic-stage`, where hooks put consistent copies of the
|
||||
databases just before the run:
|
||||
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 | In `/var/backups/restic-stage` | Volumes |
|
||||
|------|--------------------------------|---------|
|
||||
| asxpio-ops | `pg_dumpall.sql`, `asxpio.dump` (`pg_dump -Fc`), `forgejo-gitea.db` | `storage_garage_meta`, `storage_garage_data` (with a fresh Garage metadata snapshot) |
|
||||
| asxpio-services | `ejabberd.sqlite`; ejabberd's Mnesia as `nightly.backup` inside `xmpp_database` | `xmpp_database`, `xmpp_tackygram` |
|
||||
| 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),
|
||||
`/opt/containerd`, and what Minecraft downloads again (`cache`,
|
||||
`libraries`, `versions`). The exact lists are `restic_paths`,
|
||||
`restic_excludes` and `restic_pre_hooks` in
|
||||
`ansible/inventory/host_vars/`.
|
||||
Prometheus and Loki's local data, and what Minecraft downloads again.
|
||||
|
||||
Three secrets are needed, and none of them may exist only on the
|
||||
servers: the Object Storage access key and secret key, and the restic
|
||||
password (`vault_restic_password` in the Ansible vault). **Without the
|
||||
password nothing can be read.**
|
||||
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 /opt/xmpp
|
||||
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, onto a fresh system
|
||||
## A whole host
|
||||
|
||||
On a host built by `nixos/README.md` (or any Linux with restic):
|
||||
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=...
|
||||
export RESTIC_PASSWORD=...
|
||||
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 # pick one; "latest" below
|
||||
restic snapshots --host asxpio-ops
|
||||
restic restore latest --host asxpio-ops --target /
|
||||
```
|
||||
|
||||
Keep every service stopped until its data is back, so nothing starts on
|
||||
an empty directory and creates fresh state where the restore will land.
|
||||
Then, on ops:
|
||||
|
||||
1. **Files.** `/etc` is restored aside, for reference only: the system's
|
||||
configuration comes from the flake.
|
||||
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.
|
||||
|
||||
```sh
|
||||
restic restore latest --target / --include /opt --include /var/backups/restic-stage
|
||||
restic restore latest --target /root/restored-etc --include /etc
|
||||
```
|
||||
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.
|
||||
|
||||
2. **Volumes** (while services still run in containers): create each
|
||||
volume, then restore into it.
|
||||
Check: the sites answer (Grafana → Probes), a git clone over SSH, an XMPP
|
||||
login, the Minecraft world, the next nightly backup.
|
||||
|
||||
```sh
|
||||
docker volume create storage_garage_meta # one per volume in the table
|
||||
restic restore latest --target / --include /var/lib/docker/volumes/storage_garage_meta
|
||||
```
|
||||
## Backups from the Debian era
|
||||
|
||||
Under Podman the volume lives in
|
||||
`/var/lib/containers/storage/volumes/<name>`: restore to a temporary
|
||||
target and move `_data` there.
|
||||
|
||||
3. **Databases**, from the staged copies rather than the live files:
|
||||
|
||||
- **Postgres** (ops): start Postgres alone on its empty data
|
||||
directory, then load everything, roles included:
|
||||
|
||||
```sh
|
||||
psql -U postgres -f /var/backups/restic-stage/pg_dumpall.sql
|
||||
```
|
||||
|
||||
`asxpio.dump` is the same database in `pg_restore` format, for
|
||||
restoring only that one.
|
||||
- **Forgejo** (ops): `cp /var/backups/restic-stage/forgejo-gitea.db
|
||||
/opt/forgejo/data/gitea/gitea.db`, owner as the file it replaces.
|
||||
- **Garage** (ops): if it does not start on the restored metadata, use
|
||||
the snapshot inside the metadata volume (`snapshots/`), as described
|
||||
in Garage's [recovery documentation](https://garagehq.deuxfleurs.fr/documentation/operations/recovering/).
|
||||
- **ejabberd** (services): replace `ejabberd.sqlite` in `xmpp_database`
|
||||
with the staged copy; if Mnesia does not come up clean,
|
||||
`ejabberdctl restore /opt/ejabberd/database/nightly.backup`.
|
||||
|
||||
4. **Start the services**, then check: the sites answer, a `git clone`
|
||||
from Forgejo works, an XMPP client logs in, the Minecraft world is the
|
||||
expected one, and the next nightly backup succeeds.
|
||||
|
||||
The app stacks on ops (asxpio, datacenterbingo, blog, czsk, vhpbot,
|
||||
storage) come back with `/opt/<app>` (compose file and `.env`); their
|
||||
images are pulled from the registry in Forgejo, so Forgejo and storage
|
||||
come first. If the registry copy is gone, re-run each app's CI.
|
||||
|
||||
## Onto a NixOS host
|
||||
|
||||
The backup made by a NixOS host holds the new layout (`/var/lib/forgejo`,
|
||||
`/var/lib/garage`, `/var/lib/minecraft`, ...): restore to `/`, load the
|
||||
Postgres dump, `touch /var/lib/.data-in-place`, start the services.
|
||||
|
||||
A backup made while the host was still Debian holds the layout described
|
||||
above. Restore it to a side directory and let the migration script move
|
||||
it into place; this is what was rehearsed on 2026-11-16:
|
||||
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
|
||||
restic restore latest --host asxpio-ops --target /restore
|
||||
bash nixos/migration/ops-data.sh /restore # or services-data.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
|
||||
|
||||
A restore that was never tried is a hope. After any 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-16, both hosts, onto the NixOS
|
||||
rehearsal pair (Traefik, monitoring, the app stacks and XMPP not yet
|
||||
part of it).
|
||||
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).
|
||||
|
|
|
|||
Loading…
Reference in a new issue