apps(backup): cover the remaining stateful gaps off-host

Four pieces of state were still only on the machine they run on. All four now
land on the Linode over the WireGuard mesh, in the same /root/cluster-backup
tree (or /root/pihost-backup for the Pi) with the same manifest/sha256 habit:

* monitoring/kube-prometheus-stack-grafana — new CronJob `monitoring/grafana-backup`.
  The image is -distroless (no shell), so this mounts the PVC read-write and
  takes a consistent copy with the sqlite backup API (PRAGMA integrity_check on
  the copy), then streams it: grafana/grafana-<stamp>.db, keep 14.
* osint/osint-db — plain Postgres Deployment, so neither the CNPG primary lookup
  nor CNPG_TARGETS reaches it. `forgejo/cluster-backup` gains a PG_TARGETS loop
  that pg_dump -Fc's inside the pod using its own POSTGRES_USER/POSTGRES_DB
  (exec-only RBAC in apps/base/osint/), sha256 checked on both sides.
* sirius-growth/sgs-leadgen-data — new CronJob `sirius-growth/leadgen-backup`,
  link-dest snapshot mirror, keep 7.
* Pi /etc/wireguard + wgportal sqlite — infrastructure/wireguard/backup/,
  nightly systemd timer -> [email protected]:/root/pihost-backup, keep 14.

Each tree carries its own retention, so adding artifacts cannot crowd the
Linode. Docs §8/§8.1/§8.2 record coverage, the accepted gaps (Prometheus TSDB,
camera frames, runner scratch) and the restore procedure — including the
TimescaleDB pre/post-restore calls osint needs.
This commit is contained in:
Lance Walters 2026-11-19 17:14:36 -05:00
commit c1fe485469
12 changed files with 713 additions and 18 deletions

View file

@ -485,9 +485,9 @@ StorageClass `local-path` (default, `WaitForFirstConsumer`, no expansion), provi
| `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)** |
| `osint-pgdata` / `osint-camera-snapshots` | osint | 15 Gi / 3 Gi | — | 289 M / 4 K | plain Postgres — **backed up nightly (pg_dump)**; the camera snapshot dir is 4 K of throwaway frames — **accepted gap** |
| `sgs-leadgen-data` | sirius-growth | 1 Gi | — | 4.9 M | lead-gen capture — **mirrored nightly** |
| `kube-prometheus-stack-grafana` | monitoring | 5 Gi | — | 55 M | Grafana sqlite: users/orgs/prefs/API keys/annotations (dashboards, datasources and alert rules are provisioned from git, so they are *not* in the db) — **snapshotted nightly** |
| `…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 **~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.
@ -496,23 +496,38 @@ Host disks *(live)*: siriussec `/` 214 G, 167 G used (**83 %**, 37 G free); rpi
### 8.1 Backup coverage
Two independent nightly paths, both **off** the T480 and **off** the Pi:
Three independent scheduled paths, all **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 * * *`
`apps/base/sirius-growth/backup-exec-rbac.yaml` and
`apps/base/osint/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/`
2. **Two small PVC mirrors into the same tree**, because a PVC can only be
mounted by a pod in its own namespace: `monitoring/grafana-backup`
(`monitoring/controllers/home/grafana-backup.yaml`, `0 3 * * *`) and
`sirius-growth/leadgen-backup` (`apps/base/sirius-growth/leadgen-backup.yaml`,
`7 3 * * *`). Both mount the claim on siriussec and stream to
`[email protected]:/root/cluster-backup`, so retention and the manifest habit
are shared with path 1.
3. **Garage object store (Pi) → same Linode**, `infrastructure/garage/backup/`
`garage-meta-backup.timer` (hourly) + `garage-data-backup.timer` (nightly) →
`[email protected]:/root/garage-backup`.
A fourth path covers the Pi's own hub state: `infrastructure/wireguard/backup/`
`wireguard-backup.timer` (nightly 04:13) → `[email protected]:/root/pihost-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 |
| `osint/osint-db` (plain Postgres Deployment, has TimescaleDB + PostGIS) | `pg_dump -Fc -Z6` **inside the pod** over the local socket, using its own `POSTGRES_USER`/`POSTGRES_DB` via exec RBAC in `osint` | `db/osint-osint-db-<stamp>.dump` | 14 |
| `grafana.db` (sqlite) | **sqlite backup API** in a `python:3.12-alpine` pod that mounts the PVC — a `cp` of a live db can capture a torn page; the image is `-distroless`, so there is no shell to exec into | `grafana/grafana-<stamp>.db` | 14 |
| `sgs-leadgen-data` PVC | `rsync -a --delete --link-dest` snapshot mirror, PVC mounted read-only | `leadgen-data/<stamp>/` + `latest` | 7 |
| Pi `/etc/wireguard/` + wgportal `sqlite.db` | Pi-side systemd timer: tarball (`/etc/wireguard` verbatim incl. `.bak` history + a sqlite-API copy of the peer db), sha256 checked on both sides | `[email protected]:/root/pihost-backup/wireguard/wireguard-<stamp>.tar.gz` | 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
@ -531,18 +546,20 @@ Two independent nightly paths, both **off** the T480 and **off** the Pi:
- 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:**
**Accepted gaps (with the reason, not just a TODO):**
- `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
- **Prometheus TSDB** (2.4 GiB) — deliberately excluded: regenerated metrics
history, and a volume loss only costs graphs, not state.
- **`osint/osint-camera-snapshots`** (4 K) — throwaway camera frames; the
camera re-captures on demand and nothing reads old frames.
- **Runner PVCs** (`forgejo-runner-amd64`, `*-dind`) — CI scratch, rebuildable
by design (the dind data-root only holds named build caches).
- **Grafana dashboards / datasources / alert rules are not in the backup and do
not need to be**: they are provisioned from `monitoring/controllers/home/`
in git. The sqlite db carries the parts git cannot rebuild — users, orgs,
preferences, annotations and API keys.
- **Pi `/etc/wireguard` is only as fresh as the last nightly run** — a peer
added today is in the db and on the Pi, and reaches the Linode at 04:13.
A new CloudNativePG cluster is **not** picked up automatically: add
`<ns>/<cluster>` to `CNPG_TARGETS` in the CronJob env *and* an equivalent
@ -572,6 +589,47 @@ ssh [email protected] 'cat /root/cluster-backup/db/forgejo-pg-<stamp>.dump' \
`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).
```bash
# 3. osint-db (plain Postgres **with TimescaleDB**): a naive pg_restore into a
# fresh database fails on hypertable catalog rows ("could not find hypertable
# with id N" / "ONLY option not supported on hypertable operations") and
# silently drops one hypertable's data. Pre/post-restore commands are
# mandatory, and the extensions must exist BEFORE them.
kubectl -n osint exec deploy/osint-db -- psql -U osint -d postgres \
-c 'create database osint_restore'
kubectl -n osint exec deploy/osint-db -- psql -U osint -d osint_restore \
-c 'create extension if not exists timescaledb' \
-c 'create extension if not exists postgis' \
-c 'select timescaledb_pre_restore()'
ssh root@10.10.0.5 'cat /root/cluster-backup/db/osint-osint-db-<stamp>.dump' \
| kubectl -n osint exec -i deploy/osint-db -- \
pg_restore -U osint -d osint_restore --no-owner --no-privileges
kubectl -n osint exec deploy/osint-db -- psql -U osint -d osint_restore \
-c 'select timescaledb_post_restore()'
# 4. Grafana: readable with the sqlite backup API and integrity_check=ok.
# Stop Grafana first (it also runs `strategy: Recreate`) so the restored file
# is not overwritten by the running instance's open handle.
kubectl -n monitoring scale deploy/kube-prometheus-stack-grafana --replicas=0
ssh root@10.10.0.5 'cat /root/cluster-backup/grafana/grafana-<stamp>.db' \
| kubectl -n monitoring exec -i <helper-pod-with-the-pvc-mounted> -- \
sh -c 'cat > /var/lib/grafana/grafana.db && chown 472:472 /var/lib/grafana/grafana.db'
kubectl -n monitoring scale deploy/kube-prometheus-stack-grafana --replicas=1
# Users come back from the db; dashboards/datasources re-provision from git.
# 5. Lead-gen capture: plain mirror — pull it back onto the claim with rsync.
rsync -a --delete root@10.10.0.5:/root/cluster-backup/leadgen-data/latest/ /leadgen/
# 6. Pi hub state (keys included — pull it to a root-only path, never a shared one).
ssh -i /home/sirius/.ssh/linode_admin root@10.20.0.1 \
'cat /root/pihost-backup/wireguard/wireguard-<stamp>.tar.gz' | sudo tar -tzf -
# stop wg-quick first: SaveConfig = true rewrites wg0.conf from the live iface
sudo wg-quick down wg0 || true
ssh -i /home/sirius/.ssh/linode_admin root@10.20.0.1 \
'cat /root/pihost-backup/wireguard/wireguard-<stamp>.tar.gz' | sudo tar -xzf - -C /
sudo systemctl start wg-quick@wg0 && sudo wg show
```
---