apps(backup): nightly Forgejo data + CNPG dumps to the Linode, and prove a restore

Nothing on this platform backed up Forgejo or the CloudNativePG databases;
docs/cluster-overview.md had claimed both must be backed up for months.

New CronJob forgejo/cluster-backup (37 2 * * * UTC, Forbid) streams to
[email protected]:/root/cluster-backup over the WireGuard mesh:

  * forgejo-data PVC mirrored with rsync --link-dest (snapshot per night,
    hardlinked, readonly PVC mount, transient upload spools excluded, rsync
    exit 24 tolerated because Forgejo is live while it runs);
  * pg_dump -Fc from inside each CNPG primary (local socket, no DB password
    in git) for forgejo/pg and sirius-growth/portal, sha256-verified on both
    sides before the .part file is renamed.

Nothing is staged on siriussec (83% full, DiskPressure hazard); the job has
an ephemeral-storage cap of 1Gi to make that structural. Job lives in ns
forgejo because a PVC cannot be mounted cross-namespace; the portal dump uses
exec-only RBAC declared in apps/base/sirius-growth/backup-exec-rbac.yaml.

Only secret is forgejo/cluster-backup-ssh (out of band, not in git):
from=-restricted ed25519 key on the Linode, host key pinned.

docs/cluster-overview.md: §8.1 coverage + honest gaps, §8.2 restore runbook,
live PVC/disk numbers corrected.
This commit is contained in:
Lance Walters 2026-11-19 17:01:05 -05:00
commit b698f23d4f
5 changed files with 405 additions and 7 deletions

View file

@ -481,16 +481,95 @@ StorageClass `local-path` (default, `WaitForFirstConsumer`, no expansion), provi
| PVC | NS | Size | On-disk dir | Used | Holds |
|---|---|---|---|---|---|
| `forgejo-data` | forgejo | 20 Gi | `pvc-75ba7bc3…_forgejo_forgejo-data` | **12 G** | Forgejo repos, LFS, avatars, attachments — **must be backed up** |
| `forgejo-runner-amd64` | forgejo | 20 Gi | `pvc-b867904c…_forgejo_forgejo-runner-amd64` | **18 G** (18 G of it the dind `/docker` data-root) | CI scratch — **disposable**, but see the hazard below |
| `pg-1` | forgejo | 10 Gi | `pvc-3c0ba824…_forgejo_pg-1` | 643 M | Forgejo Postgres data — **must be backed up** |
| `portal-1` | sirius-growth | 5 Gi | `pvc-3348c52c…_sirius-growth_portal-1` | 224 M | SGS portal Postgres data — **must be backed up** |
| `forgejo-data` | forgejo | 20 Gi | `pvc-75ba7bc3…_forgejo_forgejo-data` | **19 G** | Forgejo repos, LFS, avatars, attachments (13.6 G of that is package-registry blobs) — **backed up nightly** |
| `forgejo-runner-amd64` | forgejo | 20 Gi | `pvc-b867904c…_forgejo_forgejo-runner-amd64` | **22 G** (the dind `/docker` data-root) | CI scratch — **disposable**, but see the hazard below |
| `pg-1` | forgejo | 10 Gi | `pvc-3c0ba824…_forgejo_pg-1` | 653 M | Forgejo Postgres data — **backed up nightly (pg_dump)** |
| `portal-1` | sirius-growth | 5 Gi | `pvc-3348c52c…_sirius-growth_portal-1` | 595 M | SGS portal Postgres data — **backed up nightly (pg_dump)** |
| `osint-pgdata` / `osint-camera-snapshots` | osint | 15 Gi / 3 Gi | — | 289 M / 4 K | plain Postgres + camera snapshots — **no backup job (gap)** |
| `sgs-leadgen-data` | sirius-growth | 1 Gi | — | 4.9 M | lead-gen capture — **no backup job (gap)** |
| `kube-prometheus-stack-grafana` | monitoring | 5 Gi | — | 55 M | Grafana sqlite (dashboards, alert rules) — **no backup job (gap)** |
| `…prometheus-…-db-…prometheus-0` | monitoring | 10 Gi | — | 2.4 G | Prometheus TSDB — rebuildable metrics history, **not backed up** |
**Dind growth hazard.** The amd64 runner's PVC is nominally 20 Gi and currently sits at **18 G (90%)**. It has previously grown to ~50 GB from heavy Android/Rust builds and pushed the node into `DiskPressure`, which evicted the runner and left Forgejo and `pg-1` Pending. Docker image GC does not reclaim the data-root. Rule: when it approaches the cap, scale the runner to 0 **first**, then wipe `.../docker/*` (keeping `runner.ini` beside it), then scale back and re-pull the job image — wiping it under a live or restarting pod leaves `dockerd` half-initialised and every pull fails. Note the data-root also hosts the named volumes CI depends on (`cargo-target`, Android SDK, Gradle cache), so a wipe makes the next run fully cold.
**Dind growth hazard.** The amd64 runner's PVC is nominally 20 Gi and currently sits at **~22 G**: it has previously grown to ~50 GB from heavy Android/Rust builds and pushed the node into `DiskPressure`, which evicted the runner and left Forgejo and `pg-1` Pending. Docker image GC does not reclaim the data-root. Rule: when it approaches the cap, scale the runner to 0 **first**, then wipe `.../docker/*` (keeping `runner.ini` beside it), then scale back and re-pull the job image — wiping it under a live or restarting pod leaves `dockerd` half-initialised and every pull fails. Note the data-root also hosts the named volumes CI depends on (`cargo-target`, Android SDK, Gradle cache), so a wipe makes the next run fully cold.
**What must be backed up:** `forgejo-data`, both Postgres data dirs (`pg-1`, `portal-1`), the Pi's Garage `data/` + `meta/`, and `/etc/wireguard/` on the Pi. The runner PVC and the Pi's Docker images are rebuildable.
Host disks *(live)*: siriussec `/` 214 G, 167 G used (**83 %**, 37 G free); rpi `/` 917 G, 506 G used (58 %, 374 G free); linode `/` 79 G, 11 G used (**14 %**, 64 G free — this is the backup target).
### 8.1 Backup coverage
Two independent nightly paths, both **off** the T480 and **off** the Pi:
1. **Cluster state → Linode VPS**, CronJob `forgejo/cluster-backup`
(`apps/base/forgejo/cluster-backup.yaml`; exec-only RBAC in
`apps/base/sirius-growth/backup-exec-rbac.yaml`). Schedule `37 2 * * *`
UTC, `concurrencyPolicy: Forbid`. Destination is
`[email protected]:/root/cluster-backup` — **the mesh address, never the public
IP**. Everything is streamed: no dump is staged on siriussec.
2. **Garage object store (Pi) → same Linode**, `infrastructure/garage/backup/`
`garage-meta-backup.timer` (hourly) + `garage-data-backup.timer` (nightly) →
`[email protected]:/root/garage-backup`.
| Artifact | Method | On the Linode | Retention |
|---|---|---|---|
| `forgejo-data` PVC (`/data`) | `rsync -a --delete --link-dest` snapshot mirror, PVC mounted read-only | `forgejo-data/<stamp>/` + `latest` symlink | 7 snapshots (hardlinked: 1 full copy + nightly deltas) |
| `forgejo/pg` | `pg_dump -Fc -Z6` **inside the CNPG primary** over the local socket — no DB password exists in git or in the Job | `db/forgejo-pg-<stamp>.dump` | 14 |
| `sirius-growth/portal` | same, through exec RBAC in `sirius-growth` | `db/sirius-growth-portal-<stamp>.dump` | 14 |
- The data mirror is a *snapshot* mirror, not a rolling one: each night writes a
new directory whose unchanged files are hardlinks to the previous night's, so
a corrupted file in the source cannot rewrite history.
- DB dumps are checksummed on **both** sides (`sha256sum` on the pod's copy of
the stream vs the remote file) before the `.part` file is renamed; a short
stream fails the Job instead of silently shipping a broken archive.
- Each run appends sizes + checksums to `/root/cluster-backup/manifests/<stamp>.txt`.
- The only secret is the backup SSH key: `forgejo/cluster-backup-ssh` (created
out of band, **not in git**, so Flux never reverts it) holding an ed25519 key
that is `from="10.10.0.0/24,10.244.0.0/16,10.20.0.0/24"`-restricted,
`no-pty`, no forwarding in `root@linode:~/.ssh/authorized_keys`. Host key is
pinned (`known_hosts` for `10.10.0.5`), so a MITM on the mesh fails closed.
- The Job lives in namespace `forgejo` (not a `backup` namespace) because a PVC
cannot be mounted cross-namespace and `forgejo-data` is the largest artifact.
**Not covered — honest gaps:**
- `monitoring/kube-prometheus-stack-grafana` (55 MiB sqlite: dashboards, alert
rules) — **no backup**. Prometheus' 2.4 GiB TSDB is deliberately excluded
(regenerated metrics history).
- `osint/osint-pgdata` (289 MiB, a plain Postgres **Deployment**, not CNPG) and
`osint/osint-camera-snapshots`, `sirius-growth/sgs-leadgen-data` (4.9 MiB) —
**no backup**.
- `/etc/wireguard/` on the Pi — still only on the Pi (wgportal's sqlite is the
live source; a Pi disk loss takes the peer set with it).
- The runner PVCs (`forgejo-runner-amd64`, `*-dind`) are CI scratch, rebuildable
by design (the dind data-root only holds named build caches).
A new CloudNativePG cluster is **not** picked up automatically: add
`<ns>/<cluster>` to `CNPG_TARGETS` in the CronJob env *and* an equivalent
exec-only Role/RoleBinding for the `forgejo/cluster-backup` ServiceAccount in
that namespace.
### 8.2 Restoring
Rehearsed on 2026-11-19 (see the completion note on task `t_dcad85f6`); the DB
restore below was exercised against a throwaway Postgres pod and produced the
live row count.
```bash
# 1. Forgejo data: stop Forgejo, then mirror the newest snapshot back.
kubectl -n forgejo scale deploy/forgejo --replicas=0
# on the node holding the PVC (siriussec), or from any pod that mounts it:
# rsync -a --delete root@10.10.0.5:/root/cluster-backup/forgejo-data/latest/ /data/
kubectl -n forgejo scale deploy/forgejo --replicas=1
# 2. A CNPG database: pull the dump and restore it with pg_restore, e.g. into a
# scratch pod or a scratch database on the cluster:
ssh root@10.10.0.5 'cat /root/cluster-backup/db/forgejo-pg-<stamp>.dump' \
| kubectl -n forgejo exec -i <pod> -c postgres -- \
pg_restore -U postgres -d <target-db> --no-owner --no-privileges
```
`pg_restore` is **not** installed on the Linode — pull the dump and restore with
a Postgres client (the `ghcr.io/cloudnative-pg/postgresql:16` primary has one).
Host disks *(live)*: siriussec `/` 214 G, 141 G used (**70%**, 62 G free); rpi `/` 917 G, 506 G used (58%, 374 G free).
---