backup(portal): barman-cloud PITR via a Linode-side Garage WAL archive #19

Merged
sirius merged 1 commit from feat/t_ce7d6772-pitr into master 2026-11-19 22:51:49 +00:00
Owner

What this does

sirius-growth/portal had a 24 h-RPO nightly pg_dump and no way to roll forward — a bad write at 14:00 lost everything since 02:37. This adds continuous WAL archiving plus a daily base backup into a second, independent Garage node on the Linode, and proves a restore to a point in time end to end.

The primary (siriussec) and the Pi's Garage are in the same building on the same power domain and uplink, so the archive deliberately does not go to the Pi's store. It goes to the Linode, which is the only off-site box in the estate.

1. S3 target on the Linode — infrastructure/garage-linode/

A separate single-node Garage (dxflrs/garage:v1.1.0, same pinned tag as the Pi) — not a peer of the Pi's node d053db4dfc97bf78: own node_key, own meta/, replication_factor = 1, capacity 20 GB.

  • Runtime is podman + a quadlet unit, not the Pi's compose file. linode is a kubelet node: installing dockerd beside its containerd would add a second runtime for nothing. One declarative /etc/containers/systemd/garage.container, systemd owns the lifecycle, no daemon.
  • Bound to 10.10.0.5 only — garage.toml binds 10.10.0.5:3900 (S3) and 10.10.0.5:3903 (admin/metrics). No 0.0.0.0 listener anywhere, eth0 (public) never bound.
  • nft guard inet wal_archive_guard, PREROUTING priority -140: accept lo/wg0 (+ 10.244.0.0/16 for local pods), drop the rest, counters on both rules. Same pattern as the Pi's garage-firewall.nft; ufw alone would not cover a container publish.
  • Bucket pg-wal-archive, private, Website access: false. Key cnpg-portal-wal (GK7f2b4bb1fc9abaec50fde37b) is read+write on that bucket only, no bucket-create. Values are in Secret sirius-growth/portal-wal-s3 — not in git, not in this PR, not in any comment.
  • install.sh (idempotent), README.md (ports, exposure proof, sizing, retention), pitr-restore.md (the rehearsal transcript).

Disk sizing (measured)

Linode / 79 G, 29 G used, 46 G free
Garage capacity 20 GB (layout) — the store stops accepting before the disk does
After the first base backup + 7 WAL segments 4.9 MB in 8 objects (data/ 9.3 MB incl. block-store overhead, meta/ 4.6 MB)
archive_timeout / wal_segment_size 5 min / 16 MB → ≤288 segments/day
Quiet steady state ~6 MB WAL/day + 4.5 MB base backup/day ≈ 150 MB per 14-day window
Worst case (every segment full, 3–5× gzip) ~1.5 GB/day ≈ 21 GB per 14 days → would hit the 20 GB cap

The 20 GB cap is intentional: at the cap Garage returns 507 InsufficientStorage and the Backup/ScheduledBackup goes red instead of the Linode disk filling. The response then is retentionPolicy: 7d, not deleting WALs by hand.

2. CNPG barman-cloud for sirius-growth/portal only

  • apps/base/sirius-growth/cluster.yaml: spec.backup.barmanObjectStore, destinationPath: s3://pg-wal-archive (bucket root — barman appends the server name, so the prefix is portal/base + portal/wals, and forgejo/pg can share the bucket later without colliding), endpointURL: http://10.10.0.5:3900, gzip on WAL and data, retentionPolicy: "14d".
  • apps/base/sirius-growth/scheduled-backup.yaml: ScheduledBackup portal-daily, 0 20 3 * * * (six-field, seconds first) = 03:20 UTC.
  • Why in-tree barmanObjectStore and not the CNPG-I plugin: the operator (1.30.0, pinned in infrastructure/databases/base/upstream/) still ships barman-cloud in-tree and it is the same binaries; the plugin would add a Deployment + CNPG-I registration + TLS to keep alive on a 3-node homelab. The operator is explicit that 1.31 removes the in-tree path, so this is documented in §8.1 as a hard migration gate before any 1.31 bump. Say the word if you'd rather I do the plugin now and hold this PR.
  • forgejo/pg is not touched on this pass (a day of git history is annoying, not costly).

3. PITR is proven, not asserted

  1. Marker row at 22:35:06.127Z, WAL switch + archive (…059 archived 22:35:07Z).
  2. 10 s later the unwanted row: 22:35:28.959Z, switch + archive (…05A archived 22:35:29Z). Both WALs are in the archive — the restore has to choose to stop, it is not starved of data.
  3. Throwaway Cluster portal-pitr-test with bootstrap.recovery → externalClusters (serverName: portal) and targetTime: 2026-11-19T22:35:15Z.
$ kubectl -n sirius-growth exec portal-pitr-test-1 -c postgres -- \
    psql -U postgres -d portal -c "select id, note, at from pitr_probe order by id"
 id |         note         |              at
----+----------------------+-------------------------------
  3 | MARKER-before-target | 2026-11-19 22:35:06.127778+00
(1 row)

$ ... -tAc "select count(*) from pitr_probe where note like 'POISON%'"
0

Rest of the database came back too (physical restore): clients 4 = 4, calendar_tokens 3 = 3, applications 1 = 1. Test cluster deleted afterwards, probe table dropped from the primary; nothing was written to production data.

4. Live evidence

# bucket, from inside the cluster over the mesh
2026-11-19 22:34:59    1.4 KiB portal/base/20261119T223452/backup.info
2026-11-19 22:34:58    4.5 MiB portal/base/20261119T223452/data.tar.gz
2026-11-19 22:35:06   20.8 KiB portal/wals/0000000100000000/000000010000000000000059.gz
2026-11-19 22:35:29   16.2 KiB portal/wals/0000000100000000/00000001000000000000005A.gz
2026-11-19 22:40:30   16.1 KiB portal/wals/0000000100000000/00000001000000000000005B.gz
Total Objects: 8   Total Size: 4857297

# listeners on the Linode
LISTEN 0 1024 10.10.0.5:3900 0.0.0.0:*   users:(("garage",pid=79464,fd=30))
LISTEN 0 1024 10.10.0.5:3903 0.0.0.0:*   users:(("garage",pid=79464,fd=31))

# off-mesh scan: from the laptop straight to the Linode public IP, no VPN in the path
port 3900 filtered/closed
port 3903 filtered/closed

# nft counters proving it is the table dropping, not a missing listener
iifname { "lo", "wg0" } tcp dport { 3900, 3903 } counter packets 4728 bytes 10030961 accept
tcp dport { 3900, 3903 } counter packets 23 bytes 1380 drop

# anonymous S3 GET on the bucket
403 AccessDenied ("Garage does not support anonymous access yet")

5. Existing job unchanged

sirius-growth/portal stays in CNPG_TARGETS as a logical second copy: it is readable with plain pg_restore on any box, it does not depend on barman or on the Linode Garage node, and it is the fallback if the archive is ever unusable. The RPO now comes from the WAL archive, not from the dump, so the dump is redundancy rather than the primary. forgejo/pg and osint/osint-db keep their nightly dumps unchanged.

6. Docs

docs/cluster-overview.md: new §5.1 (the WAL store: where, ports, firewall, node id, key scope), §8.1 counts five paths, the coverage table row shows both copies, the sizing/deprecation/credentials bullets are added, the "no PITR" gap is explicitly closed, and the "a new CNPG cluster is not picked up automatically" note now covers barman prefixes. New §8.3 is the restore recipe (target time → throwaway cluster → verify → cut over), plus the gotchas that cost time (Flux owns cluster.yaml; six-field cron; serverName; pg_is_in_recovery() = f on a promoted single-instance recovery cluster).

Notes for the merge

  • Applying this by hand is not durable: Flux owns apps/base/sirius-growth/cluster.yaml and reverts a manual spec.backup within its 1 min interval. After merge Flux applies within ~60 s; verify with
    kubectl -n sirius-growth get cluster portal -o jsonpath='{.spec.backup.barmanObjectStore.destinationPath}'.
  • infrastructure/garage-linode/ is not Flux-applied (same as the Pi's Garage); the Linode was installed from it with install.sh, and the bucket/key/Secret exist already.
  • Nothing secret is in this PR: only the Garage key ID and its scope appear.
## What this does `sirius-growth/portal` had a 24 h-RPO nightly `pg_dump` and **no way to roll forward** — a bad write at 14:00 lost everything since 02:37. This adds continuous WAL archiving plus a daily base backup into a **second, independent Garage node on the Linode**, and proves a restore to a point in time end to end. The primary (`siriussec`) and the Pi's Garage are in the same building on the same power domain and uplink, so the archive deliberately does **not** go to the Pi's store. It goes to the Linode, which is the only off-site box in the estate. ## 1. S3 target on the Linode — `infrastructure/garage-linode/` A separate single-node Garage (`dxflrs/garage:v1.1.0`, same pinned tag as the Pi) — **not** a peer of the Pi's node `d053db4dfc97bf78`: own `node_key`, own `meta/`, `replication_factor = 1`, capacity 20 GB. - **Runtime is podman + a quadlet unit**, not the Pi's compose file. `linode` is a kubelet node: installing `dockerd` beside its containerd would add a second runtime for nothing. One declarative `/etc/containers/systemd/garage.container`, systemd owns the lifecycle, no daemon. - **Bound to `10.10.0.5` only** — `garage.toml` binds `10.10.0.5:3900` (S3) and `10.10.0.5:3903` (admin/metrics). No `0.0.0.0` listener anywhere, `eth0` (public) never bound. - **nft guard** `inet wal_archive_guard`, PREROUTING priority -140: accept `lo`/`wg0` (+ `10.244.0.0/16` for local pods), drop the rest, counters on both rules. Same pattern as the Pi's `garage-firewall.nft`; ufw alone would not cover a container publish. - Bucket `pg-wal-archive`, private, `Website access: false`. Key `cnpg-portal-wal` (`GK7f2b4bb1fc9abaec50fde37b`) is **read+write on that bucket only**, no bucket-create. Values are in Secret `sirius-growth/portal-wal-s3` — not in git, not in this PR, not in any comment. - `install.sh` (idempotent), `README.md` (ports, exposure proof, sizing, retention), `pitr-restore.md` (the rehearsal transcript). ### Disk sizing (measured) | | | |---|---| | Linode `/` | 79 G, 29 G used, **46 G free** | | Garage capacity | **20 GB** (layout) — the store stops accepting before the disk does | | After the first base backup + 7 WAL segments | **4.9 MB** in 8 objects (`data/` 9.3 MB incl. block-store overhead, `meta/` 4.6 MB) | | `archive_timeout` / `wal_segment_size` | 5 min / 16 MB → ≤288 segments/day | | Quiet steady state | ~6 MB WAL/day + 4.5 MB base backup/day ≈ **150 MB per 14-day window** | | Worst case (every segment full, 3–5× gzip) | ~1.5 GB/day ≈ 21 GB per 14 days → would hit the 20 GB cap | The 20 GB cap is intentional: at the cap Garage returns `507 InsufficientStorage` and the `Backup`/`ScheduledBackup` goes red instead of the Linode disk filling. The response then is `retentionPolicy: 7d`, not deleting WALs by hand. ## 2. CNPG barman-cloud for `sirius-growth/portal` only - `apps/base/sirius-growth/cluster.yaml`: `spec.backup.barmanObjectStore`, `destinationPath: s3://pg-wal-archive` (bucket root — barman appends the server name, so the prefix is `portal/base` + `portal/wals`, and `forgejo/pg` can share the bucket later without colliding), `endpointURL: http://10.10.0.5:3900`, gzip on WAL and data, `retentionPolicy: "14d"`. - `apps/base/sirius-growth/scheduled-backup.yaml`: `ScheduledBackup portal-daily`, `0 20 3 * * *` (**six**-field, seconds first) = 03:20 UTC. - **Why in-tree `barmanObjectStore` and not the CNPG-I plugin:** the operator (1.30.0, pinned in `infrastructure/databases/base/upstream/`) still ships barman-cloud in-tree and it is the same binaries; the plugin would add a Deployment + CNPG-I registration + TLS to keep alive on a 3-node homelab. The operator is explicit that **1.31 removes the in-tree path**, so this is documented in §8.1 as a hard migration gate before any 1.31 bump. Say the word if you'd rather I do the plugin now and hold this PR. - `forgejo/pg` is **not** touched on this pass (a day of git history is annoying, not costly). ## 3. PITR is proven, not asserted 1. Marker row at **22:35:06.127Z**, WAL switch + archive (`…059` archived 22:35:07Z). 2. 10 s later the unwanted row: **22:35:28.959Z**, switch + archive (`…05A` archived 22:35:29Z). Both WALs are in the archive — the restore has to *choose* to stop, it is not starved of data. 3. Throwaway `Cluster portal-pitr-test` with `bootstrap.recovery` → `externalClusters` (`serverName: portal`) and `targetTime: 2026-11-19T22:35:15Z`. ``` $ kubectl -n sirius-growth exec portal-pitr-test-1 -c postgres -- \ psql -U postgres -d portal -c "select id, note, at from pitr_probe order by id" id | note | at ----+----------------------+------------------------------- 3 | MARKER-before-target | 2026-11-19 22:35:06.127778+00 (1 row) $ ... -tAc "select count(*) from pitr_probe where note like 'POISON%'" 0 ``` Rest of the database came back too (physical restore): `clients 4 = 4`, `calendar_tokens 3 = 3`, `applications 1 = 1`. Test cluster deleted afterwards, probe table dropped from the primary; nothing was written to production data. ## 4. Live evidence ``` # bucket, from inside the cluster over the mesh 2026-11-19 22:34:59 1.4 KiB portal/base/20261119T223452/backup.info 2026-11-19 22:34:58 4.5 MiB portal/base/20261119T223452/data.tar.gz 2026-11-19 22:35:06 20.8 KiB portal/wals/0000000100000000/000000010000000000000059.gz 2026-11-19 22:35:29 16.2 KiB portal/wals/0000000100000000/00000001000000000000005A.gz 2026-11-19 22:40:30 16.1 KiB portal/wals/0000000100000000/00000001000000000000005B.gz Total Objects: 8 Total Size: 4857297 # listeners on the Linode LISTEN 0 1024 10.10.0.5:3900 0.0.0.0:* users:(("garage",pid=79464,fd=30)) LISTEN 0 1024 10.10.0.5:3903 0.0.0.0:* users:(("garage",pid=79464,fd=31)) # off-mesh scan: from the laptop straight to the Linode public IP, no VPN in the path port 3900 filtered/closed port 3903 filtered/closed # nft counters proving it is the table dropping, not a missing listener iifname { "lo", "wg0" } tcp dport { 3900, 3903 } counter packets 4728 bytes 10030961 accept tcp dport { 3900, 3903 } counter packets 23 bytes 1380 drop # anonymous S3 GET on the bucket 403 AccessDenied ("Garage does not support anonymous access yet") ``` ## 5. Existing job unchanged `sirius-growth/portal` **stays in `CNPG_TARGETS`** as a logical second copy: it is readable with plain `pg_restore` on any box, it does not depend on barman or on the Linode Garage node, and it is the fallback if the archive is ever unusable. The RPO now comes from the WAL archive, not from the dump, so the dump is redundancy rather than the primary. `forgejo/pg` and `osint/osint-db` keep their nightly dumps unchanged. ## 6. Docs `docs/cluster-overview.md`: new §5.1 (the WAL store: where, ports, firewall, node id, key scope), §8.1 counts five paths, the coverage table row shows both copies, the sizing/deprecation/credentials bullets are added, the "no PITR" gap is explicitly closed, and the "a new CNPG cluster is not picked up automatically" note now covers barman prefixes. New §8.3 is the restore recipe (target time → throwaway cluster → verify → cut over), plus the gotchas that cost time (Flux owns `cluster.yaml`; six-field cron; `serverName`; `pg_is_in_recovery() = f` on a promoted single-instance recovery cluster). ## Notes for the merge - Applying this by hand is **not** durable: Flux owns `apps/base/sirius-growth/cluster.yaml` and reverts a manual `spec.backup` within its 1 min interval. After merge Flux applies within ~60 s; verify with `kubectl -n sirius-growth get cluster portal -o jsonpath='{.spec.backup.barmanObjectStore.destinationPath}'`. - `infrastructure/garage-linode/` is not Flux-applied (same as the Pi's Garage); the Linode was installed from it with `install.sh`, and the bucket/key/Secret exist already. - Nothing secret is in this PR: only the Garage key **ID** and its scope appear.
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.
sirius merged commit 32a59e1051 into master 2026-11-19 22:51:49 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
sirius/homek8s!19
No description provided.