backup(portal): barman-cloud PITR via a Linode-side Garage WAL archive
sirius-growth/portal had a 24h-RPO pg_dump and no way to roll forward. This adds continuous WAL archiving + a daily base backup into a second, independent Garage node on the Linode (bucket pg-wal-archive, 10.10.0.5:3900, WireGuard-only), and proves a restore to a point in time end to end. - infrastructure/garage-linode/: podman+quadlet unit (the Linode is a kubelet node, no docker), garage.toml bound to 10.10.0.5 only, nft guard in PREROUTING -140, install.sh, README with the measured disk sizing, pitr-restore.md with the rehearsal transcript. - apps/base/sirius-growth/cluster.yaml: spec.backup.barmanObjectStore (destinationPath s3://pg-wal-archive, gzip WAL+data, retentionPolicy 14d), credentials from Secret sirius-growth/portal-wal-s3 (out of band, not in git). - apps/base/sirius-growth/scheduled-backup.yaml: ScheduledBackup portal-daily, 03:20 UTC, six-field cron. - docs/cluster-overview.md: §5.1 the WAL store, §8.1 coverage + sizing + gaps, §8.3 the PITR restore recipe. forgejo/pg is deliberately left on pg_dump only (a day of git history is annoying, not costly); portal keeps its nightly dump as the logical second copy. Rehearsed 2026-11-19: marker row at 22:35:06Z, unwanted row at 22:35:28Z, throwaway cluster restored to targetTime 22:35:15Z came back with the marker and without the later row. See infrastructure/garage-linode/pitr-restore.md.
This commit is contained in:
parent
95d807852c
commit
953be9f3cf
12 changed files with 801 additions and 9 deletions
|
|
@ -311,6 +311,28 @@ Neither hostname is in the cloudflared ingress list, and `*.lab.internal` resolv
|
|||
|
||||
**What breaks:** anything that assumes `127.0.0.1:3902` (the removed static web endpoint) is reachable from inside the pod network. It never was — a pod's `127.0.0.1` is its own netns — and the listener is now gone. Kubernetes workloads must use the `10.10.0.1:3900` S3 endpoint, or the in-image `/photos/` alias baked into the site images as a fallback. That alias is a deliberate fallback, **not** evidence the bucket is gone.
|
||||
|
||||
### 5.1 A *second*, unrelated Garage node: the WAL archive on the Linode
|
||||
|
||||
`infrastructure/garage-linode/` (not Flux-applied, like the Pi's) runs a
|
||||
single-node Garage on the **Linode hub** and holds exactly one bucket,
|
||||
`pg-wal-archive`, for CloudNativePG point-in-time recovery (§8.1, §8.3).
|
||||
|
||||
| Property | Value |
|
||||
|---|---|
|
||||
| Where | Linode VPS (`linode` node), **podman** + quadlet `/etc/containers/systemd/garage.container` — there is no Docker on a kubelet node |
|
||||
| Node | `994fd2f42ae72da6`, zone `dc1`, capacity **20 GB**, `replication_factor = 1` — a separate store with its own `node_key`, **not** a peer of the Pi's node |
|
||||
| Endpoint | `http://10.10.0.5:3900` (S3) — the dummy-k8s WireGuard address, reachable from every pod over the mesh. `:3903` metrics, mesh-only, not scraped yet |
|
||||
| Config | `garage.toml` binds those two addresses explicitly (no `0.0.0.0`), RPC secret from `/etc/garage/garage.env` (0600, not in git) |
|
||||
| Firewall | nft `inet wal_archive_guard`, PREROUTING priority -140: accept `lo`/`wg0` (+ pod CIDR), drop everything else. ufw on this host is unrelated and stays as it is |
|
||||
| State | `/var/lib/garage/{meta,data}`, covered by the nightly cluster-backup tree on the same host |
|
||||
| Bucket | `pg-wal-archive` — private (`Website access: false`, anonymous GET → 403) |
|
||||
| Keys | `cnpg-portal-wal` (`GK7f2b4bb1fc9abaec50fde37b`, RW on that bucket only) → Secret `sirius-growth/portal-wal-s3` |
|
||||
|
||||
This node exists **because of where it is**, not because the estate needed a
|
||||
second S3 service: a WAL archive on the Pi would sit in the same building, power
|
||||
domain and uplink as the CNPG primary on siriussec. Off-site or it is not a
|
||||
backup.
|
||||
|
||||
---
|
||||
|
||||
## 6. Workloads
|
||||
|
|
@ -492,11 +514,11 @@ StorageClass `local-path` (default, `WaitForFirstConsumer`, no expansion), provi
|
|||
|
||||
**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.
|
||||
|
||||
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).
|
||||
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, 29 G used (**39 %**, 46 G free — this is the backup target, and since 2026-11-19 it also hosts the `pg-wal-archive` Garage node).
|
||||
|
||||
### 8.1 Backup coverage
|
||||
|
||||
Three independent scheduled paths, all **off** the T480 and **off** the Pi:
|
||||
Five 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
|
||||
|
|
@ -515,15 +537,24 @@ Three independent scheduled paths, all **off** the T480 and **off** the Pi:
|
|||
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`.
|
||||
4. **Point-in-time recovery for `sirius-growth/portal`**, continuous WAL archiving
|
||||
+ a daily base backup straight from the CNPG operator into a **second Garage
|
||||
node running on the Linode** (`infrastructure/garage-linode/`, bucket
|
||||
`pg-wal-archive`, bucket-private, `10.10.0.5:3900` WireGuard-only). This is the
|
||||
only path with a **sub-24 h RPO**: recovery to any second inside the last 14
|
||||
days, not just "the state at 02:37". Config:
|
||||
`apps/base/sirius-growth/cluster.yaml` `spec.backup.barmanObjectStore` +
|
||||
`apps/base/sirius-growth/scheduled-backup.yaml` (`ScheduledBackup portal-daily`,
|
||||
`20 3 * * *` UTC in **six**-field cron, seconds first).
|
||||
|
||||
A fourth path covers the Pi's own hub state: `infrastructure/wireguard/backup/`
|
||||
A fifth 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 |
|
||||
| `sirius-growth/portal` | two independent copies, on purpose. **(a)** `pg_dump -Fc -Z6` **inside the CNPG primary** over the local socket, through exec RBAC in `sirius-growth` — logical, human-readable with any `pg_restore`. **(b)** barman-cloud **continuous WAL archive + daily base backup** (path 4) | (a) `db/sirius-growth-portal-<stamp>.dump`; (b) `pg-wal-archive` bucket on the Linode: `portal/base/<stamp>/` + `portal/wals/…` | (a) 14 dumps; (b) 14 days of WAL (`retentionPolicy: 14d`) |
|
||||
| `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 |
|
||||
|
|
@ -546,6 +577,44 @@ A fourth path covers the Pi's own hub state: `infrastructure/wireguard/backup/`
|
|||
- 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.
|
||||
|
||||
- **The WAL archive lives in a second Garage node on the Linode, and only there.**
|
||||
Pointing barman at the Pi's Garage would put the archive in the same building,
|
||||
power domain and uplink as the CNPG primary — a second copy of the same
|
||||
failure. `infrastructure/garage-linode/` is a *separate* single-node store
|
||||
(node `994fd2f42ae72da6`, capacity 20 GB, no relation to the Pi's
|
||||
`d053db4dfc97bf78`): podman + a quadlet unit (this host has no Docker — it is a
|
||||
kubelet node), `garage.toml` binding `10.10.0.5:3900`/`:3903` only, and an nft
|
||||
table `inet wal_archive_guard` (PREROUTING -140) that drops 3900/3903 from
|
||||
anything but `lo`/`wg0`. Measured off-mesh (from this laptop, straight to the
|
||||
Linode's public IP, no VPN in the path): 3900 and 3903 **filtered**, and the
|
||||
drop counter increments. Anonymous S3 GET on the bucket → **403 AccessDenied**.
|
||||
- **Disk sizing for the WAL archive** *(measured 2026-11-19)*: Linode `/` is 79 G
|
||||
with **46 G free**; Garage is capped at 20 GB. Actual usage after the first
|
||||
base backup + 7 WAL segments: **4.9 MB** in 8 bucket objects (`data/` 9.3 MB
|
||||
with Garage's block-store overhead, `meta/` 4.6 MB). `archive_timeout` is 5 min
|
||||
and `wal_segment_size` 16 MB, so the archive takes at most 288 segments/day;
|
||||
gzip turns a segment into 16–25 KB when the database is quiet (measured) →
|
||||
~6 MB WAL/day + a 4.5 MB base backup/day ≈ **150 MB for the whole 14-day
|
||||
window**. Worst case on a busy database (every segment full at a typical 3–5×
|
||||
gzip ratio) is ~1.5 GB/day → 21 GB for 14 days, i.e. it would hit the 20 GB
|
||||
cap. The cap is deliberate: Garage answers `507 InsufficientStorage` and
|
||||
`barman-cloud-backup` fails loudly (red `Backup`/`ScheduledBackup`) rather
|
||||
than filling the Linode disk. If that ever fires, the lever is
|
||||
`spec.backup.retentionPolicy` (7d) — not deleting WALs by hand.
|
||||
- **The barman credentials are a namespaced Secret, not git**:
|
||||
`sirius-growth/portal-wal-s3` (`ACCESS_KEY_ID` / `ACCESS_SECRET_KEY` /
|
||||
`REGION`), created out of band from Garage key `cnpg-portal-wal`
|
||||
(`GK7f2b4bb1fc9abaec50fde37b`, scope **read+write on `pg-wal-archive` only**,
|
||||
no bucket-create). Recording key IDs is fine; the values are not in git, in the
|
||||
docs, or in any comment.
|
||||
- **CNPG 1.30 still ships the in-tree barman-cloud integration, and it warns that
|
||||
1.31 removes it** (`Warning: Native support for Barman Cloud backups and
|
||||
recovery is deprecated ... Please migrate existing clusters to the new Barman
|
||||
Cloud Plugin`). That is why this is on 1.30 only: the plugin (an extra
|
||||
Deployment + CNPG-I registration + TLS) is the migration path, and it must land
|
||||
before the operator goes to 1.31. Nothing else here changes when it does — the
|
||||
bucket layout stays `portal/base` + `portal/wals`.
|
||||
|
||||
**Accepted gaps (with the reason, not just a TODO):**
|
||||
|
||||
- **Prometheus TSDB** (2.4 GiB) — deliberately excluded: regenerated metrics
|
||||
|
|
@ -561,10 +630,21 @@ A fourth path covers the Pi's own hub state: `infrastructure/wireguard/backup/`
|
|||
- **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
|
||||
exec-only Role/RoleBinding for the `forgejo/cluster-backup` ServiceAccount in
|
||||
that namespace.
|
||||
**Closed 2026-11-19 — point-in-time recovery.** There is no longer a "restore to
|
||||
02:37 or lose the day" gap: `sirius-growth/portal` can be recovered to any second
|
||||
inside the 14-day window, and that restore has been rehearsed end to end (§8.3).
|
||||
`forgejo/pg` is deliberately **not** on barman yet — a day of git history is
|
||||
annoying, not costly, and one cluster proves the pattern; `osint/osint-db` is a
|
||||
plain Deployment and cannot use CNPG backup at all.
|
||||
|
||||
A new CloudNativePG cluster is **not** picked up automatically by either
|
||||
mechanism. For dumps: 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. For barman: add `spec.backup.barmanObjectStore`
|
||||
with a `destinationPath` of `s3://pg-wal-archive` (the bucket root — the server
|
||||
name, defaulting to the cluster name, becomes the prefix, so clusters share one
|
||||
bucket without colliding), the same `sirius-growth/portal-wal-s3`-shaped Secret
|
||||
in that namespace, and a `ScheduledBackup`.
|
||||
|
||||
### 8.2 Restoring
|
||||
|
||||
|
|
@ -631,6 +711,92 @@ sudo systemctl start wg-quick@wg0 && sudo wg show
|
|||
```
|
||||
|
||||
|
||||
### 8.3 Point-in-time recovery (`sirius-growth/portal`)
|
||||
|
||||
Rehearsed end to end on **2026-11-19** (task `t_ce7d6772`) against the live
|
||||
archive: a marker row was written, 10 s later a second, unwanted row was written,
|
||||
and a throwaway cluster was restored with `targetTime` between the two. The
|
||||
marker came back, the later row did not.
|
||||
|
||||
**Step 1 — establish the target time.** Take it from the data, never from
|
||||
memory:
|
||||
|
||||
```bash
|
||||
kubectl -n sirius-growth exec portal-1 -c postgres -- \
|
||||
psql -U postgres -d portal -tAc "select max(updated_at) from leads" # or pg_last_xact_replay_timestamp-style reasoning
|
||||
date -u +%FT%TZ
|
||||
```
|
||||
|
||||
**Step 2 — restore into a throwaway cluster.** Never into `portal` itself while
|
||||
it is serving: CNPG recovery bootstraps a *new* data dir from the archive.
|
||||
|
||||
```yaml
|
||||
apiVersion: postgresql.cnpg.io/v1
|
||||
kind: Cluster
|
||||
metadata:
|
||||
name: portal-pitr-test
|
||||
namespace: sirius-growth
|
||||
spec:
|
||||
instances: 1
|
||||
imageName: ghcr.io/cloudnative-pg/postgresql:16
|
||||
storage: {size: 5Gi, storageClass: local-path}
|
||||
affinity: {nodeSelector: {kubernetes.io/hostname: siriussec}}
|
||||
bootstrap:
|
||||
recovery:
|
||||
source: portal-wal
|
||||
recoveryTarget:
|
||||
targetTime: "2026-11-19T22:35:15Z" # UTC, RFC3339
|
||||
externalClusters:
|
||||
- name: portal-wal
|
||||
barmanObjectStore:
|
||||
destinationPath: s3://pg-wal-archive
|
||||
endpointURL: http://10.10.0.5:3900
|
||||
serverName: portal # MUST be the *source* cluster name
|
||||
s3Credentials:
|
||||
accessKeyId: {name: portal-wal-s3, key: ACCESS_KEY_ID}
|
||||
secretAccessKey: {name: portal-wal-s3, key: ACCESS_SECRET_KEY}
|
||||
region: {name: portal-wal-s3, key: REGION}
|
||||
```
|
||||
|
||||
```bash
|
||||
kubectl apply -f portal-pitr-test.yaml
|
||||
kubectl -n sirius-growth get cluster portal-pitr-test -w # Ready=True, "Cluster in healthy state"
|
||||
```
|
||||
|
||||
**Step 3 — verify the cut, and then promote the result.**
|
||||
|
||||
```bash
|
||||
# the restore must stop before the unwanted transaction
|
||||
kubectl -n sirius-growth exec portal-pitr-test-1 -c postgres -- \
|
||||
psql -U postgres -d portal -c "select id, note, at from <the table> order by id"
|
||||
kubectl -n sirius-growth exec portal-pitr-test-1 -c postgres -- \
|
||||
psql -U postgres -tAc "select pg_is_in_recovery(), pg_last_xact_replay_timestamp()"
|
||||
```
|
||||
|
||||
`pg_is_in_recovery() = f` on a single-instance recovery cluster means replay
|
||||
finished and it has already been promoted. **A recovery cluster is writable the
|
||||
moment it is Ready** — do not leave `portal-pitr-test` running, and do not point
|
||||
application traffic at it.
|
||||
|
||||
**Step 4 — make it the real one.** Two supported shapes: cut the app over to the
|
||||
restored cluster (preferred — reversible), or re-point the PVC:
|
||||
|
||||
```bash
|
||||
# cut over: patch the API/portal Deployments' POSTGRES_HOST to portal-pitr-test-rw,
|
||||
# then, once verified, keep it and delete the old cluster.
|
||||
# in-place: let the recovery cluster finish, stop portal, and restore the portal-1
|
||||
# PVC from the test cluster's data dir — only after the app is confirmed correct.
|
||||
```
|
||||
|
||||
**What recovery does not do:** it does not replay anything after the target, so
|
||||
a "restore to now" is only as good as the last archived WAL. If
|
||||
`pg_stat_archiver.failed_count` is non-zero, fix archiving *before* relying on a
|
||||
timestamp near the present.
|
||||
|
||||
**If the archive is lost or corrupt:** fall back to the nightly `pg_dump`
|
||||
(§8.2 step 2) — 24 h RPO, logical, and readable without barman. That is exactly
|
||||
why `sirius-growth/portal` stayed in `CNPG_TARGETS`.
|
||||
|
||||
---
|
||||
|
||||
## 9. Known hazards and runbook pointers
|
||||
|
|
|
|||
Loading…
Reference in a new issue