Merge pull request 'docs(pitr): plugin-path transcript, restore recipe, metrics, and the closed 1.31 gate' (#22) from feat/t_5df331de-barman-plugin into master

This commit is contained in:
sirius 2026-11-19 23:09:32 +00:00
commit 53a38fe022
5 changed files with 224 additions and 105 deletions

View file

@ -333,6 +333,12 @@ 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 domain and uplink as the CNPG primary on siriussec. Off-site or it is not a
backup. backup.
Producer: the **CNPG-I Barman Cloud plugin** (`cnpg-system/barman-cloud`,
`ObjectStore sirius-growth/portal-wal`) — not the operator's deprecated in-tree
`barmanObjectStore`. The bucket, key and layout are unchanged (`portal/base/…`,
`portal/wals/…`), because the plugin appends the same barman server name
(`portal`) to the same `s3://pg-wal-archive` root. See §8.4.
--- ---
## 6. Workloads ## 6. Workloads
@ -388,9 +394,10 @@ Nothing runs on `linode` except its Cilium agent. `rpi` runs only the two runner
| `kube-system` | 45 d | control plane, Cilium, Envoy, CoreDNS, hubble-relay + hubble-ui | | `kube-system` | 45 d | control plane, Cilium, Envoy, CoreDNS, hubble-relay + hubble-ui |
| `kube-public`, `kube-node-lease`, `default` | 45 d | kubeadm defaults | | `kube-public`, `kube-node-lease`, `default` | 45 d | kubeadm defaults |
| `forgejo` | 45 d | Forgejo, its CNPG cluster, 3 runners, prune CronJob | | `forgejo` | 45 d | Forgejo, its CNPG cluster, 3 runners, prune CronJob |
| `cnpg-system` | 45 d | CloudNativePG operator | | `cnpg-system` | 45 d | CloudNativePG operator **+ the CNPG-I Barman Cloud plugin** (`barman-cloud`, §8.4) |
| `cert-manager` | 1 m | cert-manager v1.21.3 (controller + webhook + cainjector) — installed for the Barman Cloud plugin's mTLS pair, §8.4 |
| `monitoring` | 1 d | kube-prometheus-stack: Prometheus (7d/8GB), Grafana, kube-state-metrics, node-exporter | | `monitoring` | 1 d | kube-prometheus-stack: Prometheus (7d/8GB), Grafana, kube-state-metrics, node-exporter |
| `flux-system` | 41 d | 4 Flux controllers, GitRepository, 4 Kustomizations | | `flux-system` | 41 d | 4 Flux controllers, GitRepository, 7 Kustomizations (`flux-system`, `gateway-api-crds`, `cert-manager`, `databases`, `infrastructure`, `monitoring`, `apps`) |
| `gateway-system` | 45 d | Gateway `public` | | `gateway-system` | 45 d | Gateway `public` |
| `internal` | 41 d | Gateways `internal` (8081) and `hubble-ui` (8084) | | `internal` | 41 d | Gateways `internal` (8081) and `hubble-ui` (8084) |
| `local-path-storage` | 45 d | provisioner | | `local-path-storage` | 45 d | provisioner |
@ -538,14 +545,18 @@ Five independent scheduled paths, all **off** the T480 and **off** the Pi:
`garage-meta-backup.timer` (hourly) + `garage-data-backup.timer` (nightly) → `garage-meta-backup.timer` (hourly) + `garage-data-backup.timer` (nightly) →
`[email protected]:/root/garage-backup`. `[email protected]:/root/garage-backup`.
4. **Point-in-time recovery for `sirius-growth/portal`**, continuous WAL archiving 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 + a daily base backup straight from the **CNPG-I Barman Cloud plugin** into a
node running on the Linode** (`infrastructure/garage-linode/`, bucket **second Garage node running on the Linode** (`infrastructure/garage-linode/`,
`pg-wal-archive`, bucket-private, `10.10.0.5:3900` WireGuard-only). This is the bucket `pg-wal-archive`, bucket-private, `10.10.0.5:3900` WireGuard-only). This
only path with a **sub-24 h RPO**: recovery to any second inside the last 14 is the only path with a **sub-24 h RPO**: recovery to any second inside the last
days, not just "the state at 02:37". Config: 14 days, not just "the state at 02:37". Config:
`apps/base/sirius-growth/cluster.yaml` `spec.backup.barmanObjectStore` + `apps/base/sirius-growth/objectstore-portal-wal.yaml` (`ObjectStore portal-wal`,
`apps/base/sirius-growth/scheduled-backup.yaml` (`ScheduledBackup portal-daily`, store + `retentionPolicy: 14d`), the Cluster's `spec.plugins`
`20 3 * * *` UTC in **six**-field cron, seconds first). (`barman-cloud.cloudnative-pg.io`, `isWALArchiver: true`, `serverName: portal`)
and `apps/base/sirius-growth/scheduled-backup.yaml` (`ScheduledBackup
portal-daily`, `20 3 * * *` UTC in **six**-field cron, seconds first,
`method: plugin`). The plugin Deployment itself is vendored in
`infrastructure/databases/base/` (§8.4).
A fifth 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`. `wireguard-backup.timer` (nightly 04:13) → `[email protected]:/root/pihost-backup`.
@ -554,7 +565,7 @@ A fifth path covers the Pi's own hub state: `infrastructure/wireguard/backup/`
|---|---|---|---| |---|---|---|---|
| `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-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 | | `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` | 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`) | | `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** through the CNPG-I plugin (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 (`ObjectStore.spec.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 | | `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 | | `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 | | `sgs-leadgen-data` PVC | `rsync -a --delete --link-dest` snapshot mirror, PVC mounted read-only | `leadgen-data/<stamp>/` + `latest` | 7 |
@ -598,22 +609,29 @@ A fifth path covers the Pi's own hub state: `infrastructure/wireguard/backup/`
window**. Worst case on a busy database (every segment full at a typical 3–5× 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 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 cap. The cap is deliberate: Garage answers `507 InsufficientStorage` and
`barman-cloud-backup` fails loudly (red `Backup`/`ScheduledBackup`) rather barman-cloud fails loudly (a red `Backup`/`ScheduledBackup`) rather
than filling the Linode disk. If that ever fires, the lever is than filling the Linode disk. If that ever fires, the lever is
`spec.backup.retentionPolicy` (7d) — not deleting WALs by hand. `ObjectStore portal-wal` → `spec.retentionPolicy` (7d) — not deleting WALs by
hand.
- **The barman credentials are a namespaced Secret, not git**: - **The barman credentials are a namespaced Secret, not git**:
`sirius-growth/portal-wal-s3` (`ACCESS_KEY_ID` / `ACCESS_SECRET_KEY` / `sirius-growth/portal-wal-s3` (`ACCESS_KEY_ID` / `ACCESS_SECRET_KEY` /
`REGION`), created out of band from Garage key `cnpg-portal-wal` `REGION`), created out of band from Garage key `cnpg-portal-wal`
(`GK7f2b4bb1fc9abaec50fde37b`, scope **read+write on `pg-wal-archive` only**, (`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 no bucket-create). Recording key IDs is fine; the values are not in git, in the
docs, or in any comment. docs, or in any comment.
- **CNPG 1.30 still ships the in-tree barman-cloud integration, and it warns that - **The 1.31 gate is closed — WAL archiving runs on the CNPG-I plugin, not the
1.31 removes it** (`Warning: Native support for Barman Cloud backups and in-tree path.** CNPG 1.30 deprecated `spec.backup.barmanObjectStore` and warns
recovery is deprecated ... Please migrate existing clusters to the new Barman on every apply that 1.31 removes it. `sirius-growth/portal` was migrated on
Cloud Plugin`). That is why this is on 1.30 only: the plugin (an extra **2026-11-19** (kanban `t_5df331de`) to the Barman Cloud plugin
Deployment + CNPG-I registration + TLS) is the migration path, and it must land (`infrastructure/databases/base/upstream/plugin-barman-cloud-0.16.0.yaml`,
before the operator goes to 1.31. Nothing else here changes when it does — the Deployment `cnpg-system/barman-cloud`, `ObjectStore sirius-growth/portal-wal`,
bucket layout stays `portal/base` + `portal/wals`. `Cluster.spec.plugins`, `ScheduledBackup.method: plugin`), so bumping the
operator pin from 1.30.0 to 1.31 no longer breaks archiving or PITR. The bucket
layout did not move: `portal/base` + `portal/wals` are the same objects the
in-tree archiver wrote, and the restore rehearsal in §8.3 ran against that
mixed archive. The plugin needs cert-manager (its mTLS pair is an
`Issuer` + two `Certificate`s), installed as `cert-manager` HelmRelease v1.21.3
— see §8.4.
**Accepted gaps (with the reason, not just a TODO):** **Accepted gaps (with the reason, not just a TODO):**
@ -640,11 +658,15 @@ plain Deployment and cannot use CNPG backup at all.
A new CloudNativePG cluster is **not** picked up automatically by either A new CloudNativePG cluster is **not** picked up automatically by either
mechanism. For dumps: add `<ns>/<cluster>` to `CNPG_TARGETS` in the CronJob env 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` *and* an equivalent exec-only Role/RoleBinding for the `forgejo/cluster-backup`
ServiceAccount in that namespace. For barman: add `spec.backup.barmanObjectStore` ServiceAccount in that namespace. For WAL archiving: create an `ObjectStore` in
with a `destinationPath` of `s3://pg-wal-archive` (the bucket root — the server that namespace whose `spec.configuration.destinationPath` is
name, defaulting to the cluster name, becomes the prefix, so clusters share one `s3://pg-wal-archive` (the bucket root — the plugin appends the barman server
bucket without colliding), the same `sirius-growth/portal-wal-s3`-shaped Secret name, which defaults to the cluster name, so clusters share one bucket without
in that namespace, and a `ScheduledBackup`. colliding), point its `s3Credentials` at a `sirius-growth/portal-wal-s3`-shaped
Secret in that namespace, give it its own `retentionPolicy`, add
`spec.plugins: [{name: barman-cloud.cloudnative-pg.io, isWALArchiver: true,
parameters: {barmanObjectName: <store>}}]` to the Cluster and a
`ScheduledBackup` with `method: plugin`.
### 8.2 Restoring ### 8.2 Restoring
@ -713,10 +735,11 @@ sudo systemctl start wg-quick@wg0 && sudo wg show
### 8.3 Point-in-time recovery (`sirius-growth/portal`) ### 8.3 Point-in-time recovery (`sirius-growth/portal`)
Rehearsed end to end on **2026-11-19** (task `t_ce7d6772`) against the live Rehearsed end to end twice: **2026-11-19** with the in-tree barman-cloud archiver
archive: a marker row was written, 10 s later a second, unwanted row was written, (task `t_ce7d6772`) and again the same day **on the CNPG-I Barman Cloud plugin**
and a throwaway cluster was restored with `targetTime` between the two. The (task `t_5df331de`, §8.4) — marker row → forced WAL switch → unwanted row →
marker came back, the later row did not. forced WAL switch → throwaway cluster restored with `targetTime` between the
two. Both times the marker came back and the later row did not.
**Step 1 — establish the target time.** Take it from the data, never from **Step 1 — establish the target time.** Take it from the data, never from
memory: memory:
@ -729,6 +752,8 @@ date -u +%FT%TZ
**Step 2 — restore into a throwaway cluster.** Never into `portal` itself while **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. it is serving: CNPG recovery bootstraps a *new* data dir from the archive.
`externalClusters[].plugin` replaces `barmanObjectStore`; `serverName` is the
barman prefix and must stay the **source** cluster name.
```yaml ```yaml
apiVersion: postgresql.cnpg.io/v1 apiVersion: postgresql.cnpg.io/v1
@ -745,17 +770,14 @@ spec:
recovery: recovery:
source: portal-wal source: portal-wal
recoveryTarget: recoveryTarget:
targetTime: "2026-11-19T22:35:15Z" # UTC, RFC3339 targetTime: "2026-11-19T23:05:00Z" # UTC, RFC3339
externalClusters: externalClusters:
- name: portal-wal - name: portal-wal
barmanObjectStore: plugin:
destinationPath: s3://pg-wal-archive name: barman-cloud.cloudnative-pg.io
endpointURL: http://10.10.0.5:3900 parameters:
serverName: portal # MUST be the *source* cluster name barmanObjectName: portal-wal # the ObjectStore in this namespace
s3Credentials: serverName: portal # MUST be the *source* cluster name
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 ```bash
@ -773,6 +795,25 @@ 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()" psql -U postgres -tAc "select pg_is_in_recovery(), pg_last_xact_replay_timestamp()"
``` ```
Rehearsal transcript on the plugin path (2026-11-19 23:04–23:06 UTC), target
`2026-11-19T23:05:00Z`, marker written 23:04:53.07, unwanted row 23:05:15.80:
```
# live primary, the mistake
1 | MARKER-plugin-before-target | 2026-11-19 23:04:53.072104+00
2 | POISON-plugin-after-target | 2026-11-19 23:05:15.798408+00
# pg_stat_archiver after forcing both segments out: ...062 (23:04:54), ...063 (23:05:16), failed_count 6 (historical, static)
# restored cluster portal-pitr-test (targetTime 23:05:00Z)
id | note | at
----+-----------------------------+-------------------------------
1 | MARKER-plugin-before-target | 2026-11-19 23:04:53.072104+00
(1 row)
select count(*) from pitr_probe where note like 'POISON%' -> 0
select pg_is_in_recovery(), pg_last_xact_replay_timestamp() -> f|
clients=4 calendar_tokens=3 applications=1 # identical to the primary
```
`pg_is_in_recovery() = f` on a single-instance recovery cluster means replay `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 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 moment it is Ready** — do not leave `portal-pitr-test` running, and do not point
@ -797,6 +838,36 @@ timestamp near the present.
(§8.2 step 2) — 24 h RPO, logical, and readable without barman. That is exactly (§8.2 step 2) — 24 h RPO, logical, and readable without barman. That is exactly
why `sirius-growth/portal` stayed in `CNPG_TARGETS`. why `sirius-growth/portal` stayed in `CNPG_TARGETS`.
### 8.4 The CNPG-I Barman Cloud plugin (how it is wired)
Active since **2026-11-19**. Three moving parts, all in git:
| Piece | Where | Notes |
|---|---|---|
| Plugin Deployment | `infrastructure/databases/base/upstream/plugin-barman-cloud-0.16.0.yaml` (vendored verbatim, sha256 `aee61468…7155`), patched only for `--log-level=info` + resources | `cnpg-system/barman-cloud`, port 9090, `replicas: 1`; **registered through Service annotations** `cnpg.io/pluginName: barman-cloud.cloudnative-pg.io` + `cnpg.io/pluginPort`/`pluginClientSecret`/`pluginServerSecret` — there is no `Plugin` CR in CNPG 1.30; delete the Service and the operator deregisters it |
| mTLS | `infrastructure/controllers/cert-manager/` (HelmRelease `cert-manager` v1.21.3, `crds.enabled: true`) issuing `barman-cloud-server-tls` / `barman-cloud-client-tls` from the vendored `Issuer` + `Certificate`s | cert-manager is a hard dependency of the plugin manifest, not a nice-to-have |
| Store + wiring | `ObjectStore sirius-growth/portal-wal`, `Cluster portal` `spec.plugins`, `ScheduledBackup portal-daily` `method: plugin` | `ObjectStore` must live in the Cluster's namespace, and its `serverName` field must stay **empty** (the CRD enforces this); the prefix comes from `spec.plugins[].parameters.serverName` |
Instance side: the operator injects an init-container sidecar
(`plugin-barman-cloud`, restartable sidecar) into `portal-1` and mounts a
`plugins` volume, which is why the Cluster restarted its primary once at
migration time. That sidecar runs `barman-cloud-wal-archive` /
`barman-cloud-backup` and enforces `retentionPolicy` every 30 min; the archive
URL it uses is `s3://pg-wal-archive portal <segment>` — same prefix as before.
Metrics change family with the archiver: `barman_cloud_cloudnative_pg_io_*`
(`…_last_available_backup_timestamp`, `…_first_recoverability_point`,
`…_last_failed_backup_timestamp`) replace `cnpg_collector_*` for this cluster.
The CNPG Grafana board accepts both. The deprecated
`cnpg_collector_last_available_backup_timestamp` is still *scraped* for portal
and holds the pre-migration value (22:34 UTC), so a panel that selects it alone
freezes at the last in-tree backup — that is why §8.4's dashboard change puts
the plugin metric first in the `or`.
Dependency order in Flux: `cert-manager` → `databases` (plugin + `ObjectStore`
CRD) → `apps` (the `ObjectStore` CR and the Cluster that references it).
--- ---
## 9. Known hazards and runbook pointers ## 9. Known hazards and runbook pointers
@ -892,3 +963,16 @@ All times 2026-10-26 UTC. `kubeconfig` on the Legion admin laptop → `https://1
| 36 | siriussec: `curl :2381/metrics` (etcd) | `wal_fsync` 158 >8.192 s / 2,518 >2.048 s of 14,813,192; `backend_commit` 187 >8.192 s of 6,652,027; 99.6 %/99.7 % ≤32 ms — matches the stated stall profile, so this is spiky contention, not a failing disk | | 36 | siriussec: `curl :2381/metrics` (etcd) | `wal_fsync` 158 >8.192 s / 2,518 >2.048 s of 14,813,192; `backend_commit` 187 >8.192 s of 6,652,027; 99.6 %/99.7 % ≤32 ms — matches the stated stall profile, so this is spiky contention, not a failing disk |
**Not verified, deliberately:** Cloudflare DNS records, Forgejo's `app.ini`, any secret material, and the SG-VPS/phone spoke routing beyond what the Linode's `wg show` reports. **Not verified, deliberately:** Cloudflare DNS records, Forgejo's `app.ini`, any secret material, and the SG-VPS/phone spoke routing beyond what the Linode's `wg show` reports.
**CNPG-I Barman Cloud plugin migration, verified 2026-11-19 22:57–23:07 UTC (commits `f3a8233`, `c452552`; kanban `t_5df331de`):**
| # | Command | Key result |
|---|---|---|
| 37 | `kubectl -n cert-manager get pods`; `kubectl -n flux-system get kustomization` | controller/webhook/cainjector `1/1 Running`; all 7 Kustomizations `Ready=True` at the same revision, `databases` `dependsOn cert-manager`, `apps` `dependsOn databases` |
| 38 | `kubectl -n cnpg-system get pods,certificate` | `barman-cloud-7b779d49d8-2pnbk 1/1 Running`; `barman-cloud-client` + `barman-cloud-server` certificates `READY=True` — the operator logged `Registered plugin` for `barman-cloud.cloudnative-pg.io` |
| 39 | `kubectl -n sirius-growth get cluster portal -o jsonpath='{.status.pluginStatus}'` | `[{name: barman-cloud.cloudnative-pg.io, version: 0.16.0, capabilities: [TYPE_RECONCILER_HOOKS, TYPE_LIFECYCLE_SERVICE, TYPE_INSTANCE_SIDECAR_INJECTION]}]`; pod `portal-1` now carries the `plugin-barman-cloud` init-sidecar and `plugins` volume; Cluster `Ready=True` |
| 40 | `kubectl -n sirius-growth logs portal-1 -c plugin-barman-cloud` | `Executing barman-cloud-wal-archive … ["--gzip","--endpoint-url","http://10.10.0.5:3900","--cloud-provider","aws-s3","s3://pg-wal-archive","portal", …05D]` → `Archived WAL file … elapsedWalTime 0.586`; retention runnable applied `14d` |
| 41 | `kubectl -n sirius-growth get backup portal-plugin-proof-1 -o wide` | `METHOD plugin`, `PHASE completed` (on-demand base backup through the plugin) |
| 42 | `aws --endpoint-url http://10.10.0.5:3900 s3 ls --recursive s3://pg-wal-archive/` (from a pod, Secret `portal-wal-s3`) | `portal/base/20261119T223452/…` (in-tree) **and** `portal/base/20261119T230300/…` (plugin) side by side, `portal/wals/…` continuous — the prefix did not move; 4 objects under `base/`, 10 under `wals/` |
| 43 | PITR rehearsal: marker `23:04:53.07`, poison `23:05:15.80`, `targetTime 2026-11-19T23:05:00Z` | restored `portal-pitr-test` → marker row present, `count(POISON%)=0`, `pg_is_in_recovery()=f`, `clients 4 / calendar_tokens 3 / applications 1` identical to the primary; test cluster + PVC deleted, probe table dropped afterwards |
| 44 | Prometheus (`/api/v1/query`) | `barman_cloud_cloudnative_pg_io_last_available_backup_timestamp` = 1795129385 (23:03:05, the plugin backup), `…_first_recoverability_point` = 1795127697; the legacy `cnpg_collector_last_available_backup_timestamp` for `portal` still returns the **pre-migration** 1795127697 — hence the dashboard's `or` lists the plugin metric first |

View file

@ -1,9 +1,9 @@
# Garage on the Linode — the CloudNativePG WAL archive # Garage on the Linode — the CloudNativePG WAL archive
A **second, independent** single-node Garage on the Linode VPS. It holds one A **second, independent** single-node Garage on the Linode VPS. It holds one
bucket, `pg-wal-archive`, and its only consumer is CloudNativePG's barman-cloud bucket, `pg-wal-archive`, and its only consumer is the **CNPG-I Barman Cloud
integration for `sirius-growth/portal` (continuous WAL archiving + daily base plugin** archiving for `sirius-growth/portal` (continuous WAL archiving + daily
backups → point-in-time recovery). base backups → point-in-time recovery).
It is **not** the Pi's Garage (`infrastructure/garage/`, node It is **not** the Pi's Garage (`infrastructure/garage/`, node
`d053db4dfc97bf78`). Different host, different `node_key`, different metadata `d053db4dfc97bf78`). Different host, different `node_key`, different metadata
@ -99,8 +99,9 @@ Measured 2026-11-19:
| Steady state (quiet) | ~6 MB WAL/day + 4.5 MB base backup/day ≈ **150 MB per 14-day window** | | Steady state (quiet) | ~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 cap | | Worst case (every segment full, 3–5× gzip) | ~1.5 GB/day ≈ 21 GB per 14 days — would hit the cap |
Retention is `spec.backup.retentionPolicy: "14d"` on the Cluster, enforced by Retention is `spec.retentionPolicy: "14d"` on the `ObjectStore` (`portal-wal` in
barman-cloud when a backup completes. The 20 GB cap is deliberate: when it is `sirius-growth`), enforced by the plugin's instance sidecar (every 30 min), not
by the Cluster. The 20 GB cap is deliberate: when it is
reached Garage returns `507 InsufficientStorage` and the `Backup` / reached Garage returns `507 InsufficientStorage` and the `Backup` /
`ScheduledBackup` goes red — a visible failure instead of a full Linode disk. `ScheduledBackup` goes red — a visible failure instead of a full Linode disk.
The response to that is to lower the retention policy to `7d`, or to grow the The response to that is to lower the retention policy to `7d`, or to grow the
@ -110,7 +111,8 @@ continuity and every PITR target that depends on the deleted segment).
## How the archive is laid out ## How the archive is laid out
`destinationPath: s3://pg-wal-archive` (bucket root) with the barman server name `destinationPath: s3://pg-wal-archive` (bucket root) with the barman server name
defaulting to the cluster name, so: explicitly set to the cluster name (`Cluster.spec.plugins[].parameters.serverName:
portal`), so:
``` ```
pg-wal-archive/portal/base/20261119T223452/{backup.info,data.tar.gz} pg-wal-archive/portal/base/20261119T223452/{backup.info,data.tar.gz}

View file

@ -1,54 +1,71 @@
# Restore notes — point-in-time recovery for `sirius-growth/portal` # Restore notes — point-in-time recovery for `sirius-growth/portal`
Rehearsed end to end on **2026-11-19** (kanban task `t_ce7d6772`) against the live Rehearsed end to end on **2026-11-19** against the live archive, twice: once with
archive. This file records the commands and the actual output of that rehearsal, the in-tree barman-cloud archiver (kanban `t_ce7d6772`) and once **after the
so the next person restores from a transcript instead of a hope. migration to the CNPG-I Barman Cloud plugin** (kanban `t_5df331de`). This file
records the commands and the actual output of the plugin rehearsal, so the next
person restores from a transcript instead of a hope.
The archive: Garage on the Linode, bucket `pg-wal-archive`, `http://10.10.0.5:3900` The archive: Garage on the Linode, bucket `pg-wal-archive`, `http://10.10.0.5:3900`
over the WireGuard mesh, credentials in Secret `sirius-growth/portal-wal-s3`. over the WireGuard mesh, credentials in Secret `sirius-growth/portal-wal-s3`.
Producer: `spec.backup.barmanObjectStore` on `Cluster sirius-growth/portal` Producer: the **Barman Cloud plugin** — `ObjectStore sirius-growth/portal-wal`
(WAL archiving continuous, `ScheduledBackup portal-daily` at 03:20 UTC, (store + `retentionPolicy: 14d`), `Cluster portal` `spec.plugins`
`retentionPolicy: 14d`). (`isWALArchiver: true`, `serverName: portal`) and `ScheduledBackup portal-daily`
at 03:20 UTC with `method: plugin`. WAL archiving is continuous; base backups are
daily plus on demand.
## 0. Is the archive actually healthy? ## 0. Is the archive actually healthy?
```bash ```bash
kubectl -n sirius-growth exec portal-1 -c postgres -- \ kubectl -n sirius-growth exec portal-1 -c postgres -- \
psql -U postgres -tAc "select last_archived_wal, last_archived_time, failed_count from pg_stat_archiver" psql -U postgres -tAc "select last_archived_wal, last_archived_time, failed_count from pg_stat_archiver"
# 00000001000000000000005B|2026-11-19 22:40:30.1+00|0 # 000000010000000000000063|2026-11-19 23:05:16.834323+00|6
``` ```
`failed_count` must be 0 and `last_archived_time` must be minutes old. A `last_archived_time` must be minutes old and the WAL name must advance when you
`targetTime` after the last archived WAL cannot be reached — recovery stops at force a segment (`select pg_switch_wal()`). A `targetTime` after the last
the last segment it can fetch. archived WAL cannot be reached — recovery stops at the last segment it can fetch.
`failed_count` is **cumulative for the life of the instance**, not a "current
health" gauge: the 6 recorded here are from the pre-migration in-tree archiver
and the primary restart during the switch. What matters is that it does not
*increase* while you watch — check it before and after a forced segment.
What actually wrote the last segment is visible in the sidecar log, which names
barman's own arguments (server name `portal`, bucket root `s3://pg-wal-archive`):
```bash ```bash
kubectl -n sirius-growth get backup -o wide # newest barmanObjectStore Backup: completed kubectl -n sirius-growth logs portal-1 -c plugin-barman-cloud --tail=20
kubectl -n sirius-growth get scheduledbackup # portal-daily, LAST BACKUP set # {"msg":"Executing barman-cloud-wal-archive", ... "options":["--gzip","--endpoint-url","http://10.10.0.5:3900",
# "--cloud-provider","aws-s3","s3://pg-wal-archive","portal","/var/lib/postgresql/data/pgdata/pg_wal/<seg>"]}
# {"msg":"Archived WAL file","walName":"...<seg>","elapsedWalTime":0.586...}
```
```bash
kubectl -n sirius-growth get backup -o wide # newest Backup: METHOD plugin, PHASE completed
kubectl -n sirius-growth get scheduledbackup # portal-daily, method plugin, LAST BACKUP set
``` ```
## 1. Prove the marker, then make the mistake ## 1. Prove the marker, then make the mistake
The rehearsal wrote a marker, forced the WAL out, waited, then wrote a second
row that must *not* survive recovery:
```bash ```bash
q() { kubectl -n sirius-growth exec portal-1 -c postgres -- psql -U postgres -d portal -tAc "$1"; } q() { kubectl -n sirius-growth exec portal-1 -c postgres -- psql -U postgres -d portal -tAc "$1"; }
q "insert into pitr_probe(note) values ('MARKER-before-target') returning id, at" q "create table if not exists pitr_probe(id bigserial primary key, note text, at timestamptz default now())"
# 3|2026-11-19 22:35:06.127778+00 q "insert into pitr_probe(note) values ('MARKER-plugin-before-target') returning id, at"
# 1|2026-11-19 23:04:53.072104+00
q "select pg_switch_wal()" ; sleep 12 q "select pg_switch_wal()" ; sleep 12
q "select last_archived_wal, last_archived_time from pg_stat_archiver" q "select last_archived_wal, last_archived_time, failed_count from pg_stat_archiver"
# 000000010000000000000059|2026-11-19 22:35:07.089783+00 # 000000010000000000000062|2026-11-19 23:04:54.052315+00|6
sleep 10 sleep 10
q "insert into pitr_probe(note) values ('POISON-after-target') returning id, at" q "insert into pitr_probe(note) values ('POISON-plugin-after-target') returning id, at"
# 4|2026-11-19 22:35:28.959782+00 # 2|2026-11-19 23:05:15.798408+00
q "select pg_switch_wal()" ; sleep 12 q "select pg_switch_wal()" ; sleep 12
q "select last_archived_wal, last_archived_time from pg_stat_archiver" q "select last_archived_wal, last_archived_time, failed_count from pg_stat_archiver"
# 00000001000000000000005A|2026-11-19 22:35:29.906592+00 # 000000010000000000000063|2026-11-19 23:05:16.834323+00|6
``` ```
The target is therefore **`2026-11-19T22:35:15Z`** — 9 s after the marker, 14 s The target is therefore **`2026-11-19T23:05:00Z`** — 7 s after the marker, 15 s
before the row that must be lost. Note that WAL `…05A` (which contains the poison before the row that must be lost. Note that WAL `…063` (which contains the poison
row) *is* in the archive: the restore has to choose to stop, it is not starved of row) *is* in the archive: the restore has to choose to stop, it is not starved of
data. data.
@ -75,23 +92,22 @@ spec:
recovery: recovery:
source: portal-wal source: portal-wal
recoveryTarget: recoveryTarget:
targetTime: "2026-11-19T22:35:15Z" targetTime: "2026-11-19T23:05:00Z"
externalClusters: externalClusters:
- name: portal-wal - name: portal-wal
barmanObjectStore: plugin: # was barmanObjectStore before the plugin migration
destinationPath: s3://pg-wal-archive name: barman-cloud.cloudnative-pg.io
endpointURL: http://10.10.0.5:3900 parameters:
serverName: portal # MUST match the source Cluster name barmanObjectName: portal-wal # ObjectStore in THIS namespace
s3Credentials: serverName: portal # MUST be the *source* Cluster name
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}
``` ```
`serverName` is not optional: it is the barman prefix (`portal/base`, `serverName` is not optional: it is the barman prefix (`portal/base`,
`portal/wals`). Omit it and the restore cluster looks for its own name and finds `portal/wals`). Omit it and the plugin falls back to the *restoring* cluster's
an empty history. `targetTime` is UTC RFC3339 — a wrong timezone silently name (`portal-pitr-test`) and finds an empty history. `targetTime` is UTC
restores the wrong hour. RFC3339 — a wrong timezone silently restores the wrong hour. The ObjectStore's
own `spec.configuration.serverName` must stay empty (its CRD rejects anything
else); the prefix always comes from this plugin parameter.
The operator restores the base backup, replays WAL, stops at the target and The operator restores the base backup, replays WAL, stops at the target and
promotes: promotes:
@ -108,9 +124,9 @@ portal-pitr-test 1 1 Cluster in healthy state portal-pitr-test-1
``` ```
$ kubectl -n sirius-growth exec portal-pitr-test-1 -c postgres -- \ $ 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" psql -U postgres -d portal -c "select id, note, at from pitr_probe order by id"
id | note | at id | note | at
----+----------------------+------------------------------- ----+-----------------------------+-------------------------------
3 | MARKER-before-target | 2026-11-19 22:35:06.127778+00 1 | MARKER-plugin-before-target | 2026-11-19 23:04:53.072104+00
(1 row) (1 row)
$ ... -tAc "select count(*) from pitr_probe where note like 'POISON%'" $ ... -tAc "select count(*) from pitr_probe where note like 'POISON%'"
@ -122,7 +138,7 @@ Marker present, post-target row gone. The rest of the database came back with it
`clients 4 = 4`, `calendar_tokens 3 = 3`, `applications 1 = 1` against the `clients 4 = 4`, `calendar_tokens 3 = 3`, `applications 1 = 1` against the
primary at that moment. primary at that moment.
``` ```bash
$ ... -tAc "select pg_is_in_recovery()" $ ... -tAc "select pg_is_in_recovery()"
f # replay finished, instance promoted f # replay finished, instance promoted
``` ```
@ -134,6 +150,8 @@ why nothing may point application traffic at it before you decide to.
```bash ```bash
kubectl -n sirius-growth delete cluster portal-pitr-test kubectl -n sirius-growth delete cluster portal-pitr-test
kubectl -n sirius-growth delete pvc -l cnpg.io/cluster=portal-pitr-test
kubectl -n sirius-growth exec portal-1 -c postgres -- psql -U postgres -d portal -tAc "drop table if exists pitr_probe"
``` ```
## 4. Making the restored data the real data ## 4. Making the restored data the real data
@ -148,29 +166,44 @@ Two shapes, both legitimate:
the recovered data directory. Slower, destructive, and easy to get wrong — the recovered data directory. Slower, destructive, and easy to get wrong —
only with the app scaled to zero. only with the app scaled to zero.
Either way, take a fresh base backup once the decision is made Either way, take a fresh base backup once the decision is made (a `Backup` CR with
(`kubectl apply` a `Backup` CR against the surviving cluster) so the archive has `method: plugin`, or `kubectl cnpg backup -n sirius-growth portal --method=plugin
a post-recovery base rather than one from before the incident. --plugin-name=barman-cloud.cloudnative-pg.io`) so the archive has a post-recovery
base rather than one from before the incident.
## Gotchas that cost time ## Gotchas that cost time
- **Flux owns `apps/base/sirius-growth/cluster.yaml`.** A hand `kubectl apply` of - **Flux owns `apps/base/sirius-growth/`.** A hand `kubectl apply` of the Cluster,
a new `spec.backup` is reverted by the `apps` Kustomization within its 1 min the ObjectStore or the ScheduledBackup is reverted by the `apps` Kustomization
interval. Config changes belong in the branch/PR. (During the rehearsal the within its 1 min interval. Config changes belong in the branch/PR. (`Cluster`
`kustomize-controller` Deployment was scaled to 0 for the test window and and `Backup` objects created by hand for a rehearsal are not in the
scaled back afterwards; `Backup`/`Cluster` objects created by hand are not in Kustomization inventory, so they are not pruned — but the objects Flux *does*
the Kustomization inventory, so they are not pruned.) own are reverted.)
- **`ScheduledBackup.spec.schedule` is six-field cron, seconds first.** `0 20 3 - **`ScheduledBackup.spec.schedule` is six-field cron, seconds first.** `0 20 3
* * *` = 03:20:00 UTC. Copying a five-field crontab string silently means * * *` = 03:20:00 UTC. Copying a five-field crontab string silently means
"every minute" in the first field. "every minute" in the first field.
- **Two different `serverName`s exist and only one may be set.** On the
`ObjectStore` it must be absent (CRD CEL rule); on the Cluster's
`spec.plugins[].parameters` / `externalClusters[].plugin.parameters` it is the
prefix. Set the wrong one and archiving writes to `portal-<something>/`, which
silently abandons the existing 14-day window.
- **The bucket prefix is `portal/portal/…` only if you get `destinationPath` - **The bucket prefix is `portal/portal/…` only if you get `destinationPath`
wrong.** Use `s3://pg-wal-archive` for the bucket root; barman appends the wrong.** Use `s3://pg-wal-archive` for the bucket root; the server name is
server name. appended.
- **CNPG 1.30 warns that in-tree barman-cloud is removed in 1.31.** If that - **Plugin, not in-tree.** The operator's in-tree barman-cloud support is
upgrade happens, migrate to the Barman Cloud Plugin first; until then the deprecated in 1.30 and removed in 1.31; `spec.backup.barmanObjectStore` on a
archives remain readable by `barman-cloud-restore` in the same container image. 1.31 operator would leave the cluster with no archiver at all. Restore config
- **If archiving has failed** (`pg_stat_archiver.failed_count > 0`), fix it and is `externalClusters[].plugin` + `parameters.barmanObjectName`, and the store
let a fresh base backup complete before trusting any recent `targetTime`. itself is an `ObjectStore` CR in the cluster's namespace.
- **Retention moved.** `retentionPolicy` lives on the `ObjectStore` now, enforced
by the plugin sidecar every 30 min — not on the Cluster, and not "at backup
time".
- **Backup metrics changed family.** `barman_cloud_cloudnative_pg_io_last_available_backup_timestamp`
replaces `cnpg_collector_last_available_backup_timestamp`. The old series for
`portal` still shows the pre-migration timestamp, so alert/dashboard queries
must prefer the new one (see `monitoring/controllers/home/dashboards/build.py`).
- **If archiving has failed** (`pg_stat_archiver.failed_count` increasing), fix it
and let a fresh base backup complete before trusting any recent `targetTime`.
- **Fallback when the archive is unusable:** the nightly `pg_dump` in - **Fallback when the archive is unusable:** the nightly `pg_dump` in
`forgejo/cluster-backup` (`db/sirius-growth-portal-<stamp>.dump`, 14 retained, `forgejo/cluster-backup` (`db/sirius-growth-portal-<stamp>.dump`, 14 retained,
§8.2 step 2 of `docs/cluster-overview.md`). 24 h RPO, logical, independent of §8.2 step 2 of `docs/cluster-overview.md`). 24 h RPO, logical, independent of

View file

@ -245,9 +245,9 @@ cnpg = [
{"h": 5, "w": 4, "x": 16, "y": 1}, {"h": 5, "w": 4, "x": 16, "y": 1},
desc="1 = the operator is asking for a manual switchover (e.g. after a fencing event).", desc="1 = the operator is asking for a manual switchover (e.g. after a fencing event).",
thresholds=[{"color": "green", "value": None}, {"color": "red", "value": 1}]), thresholds=[{"color": "green", "value": None}, {"color": "red", "value": 1}]),
stat("Last available backup", [target('max by (namespace) (cnpg_collector_last_available_backup_timestamp{%s} or barman_cloud_cloudnative_pg_io_last_available_backup_timestamp{%s})' % (CLUSTER_NS, CLUSTER_NS))], stat("Last available backup", [target('max by (namespace) (barman_cloud_cloudnative_pg_io_last_available_backup_timestamp{%s} or cnpg_collector_last_available_backup_timestamp{%s})' % (CLUSTER_NS, CLUSTER_NS))],
{"h": 5, "w": 4, "x": 20, "y": 1}, unit="dateTimeAsIso", {"h": 5, "w": 4, "x": 20, "y": 1}, unit="dateTimeAsIso",
desc="0 = never. sirius-growth/portal archives through the CNPG-I Barman Cloud plugin, which exposes its own metric family `barman_cloud_cloudnative_pg_io_*`; the in-tree `cnpg_collector_*` name is kept in the `or` for any cluster still on the deprecated path. A 0 means neither series exists.", desc="0 = never. sirius-growth/portal archives through the CNPG-I Barman Cloud plugin, whose metric is `barman_cloud_cloudnative_pg_io_last_available_backup_timestamp`; the deprecated `cnpg_collector_*` name is the fallback for any cluster still on the in-tree path. Order matters: the legacy series is still scraped for portal and holds the PRE-migration timestamp, so it must not win the `or`.",
thresholds=[{"color": "red", "value": None}, {"color": "green", "value": 1}]), thresholds=[{"color": "red", "value": None}, {"color": "green", "value": 1}]),
row("Throughput", 6), row("Throughput", 6),

View file

@ -423,7 +423,7 @@ data:
"id": 29, "id": 29,
"type": "stat", "type": "stat",
"title": "Last available backup", "title": "Last available backup",
"description": "0 = never. sirius-growth/portal archives through the CNPG-I Barman Cloud plugin, which exposes its own metric family `barman_cloud_cloudnative_pg_io_*`; the in-tree `cnpg_collector_*` name is kept in the `or` for any cluster still on the deprecated path. A 0 means neither series exists.", "description": "0 = never. sirius-growth/portal archives through the CNPG-I Barman Cloud plugin, whose metric is `barman_cloud_cloudnative_pg_io_last_available_backup_timestamp`; the deprecated `cnpg_collector_*` name is the fallback for any cluster still on the in-tree path. Order matters: the legacy series is still scraped for portal and holds the PRE-migration timestamp, so it must not win the `or`.",
"datasource": { "datasource": {
"type": "prometheus", "type": "prometheus",
"uid": "prometheus" "uid": "prometheus"
@ -440,7 +440,7 @@ data:
"type": "prometheus", "type": "prometheus",
"uid": "prometheus" "uid": "prometheus"
}, },
"expr": "max by (namespace) (cnpg_collector_last_available_backup_timestamp{namespace=~\"$namespace\"} or barman_cloud_cloudnative_pg_io_last_available_backup_timestamp{namespace=~\"$namespace\"})", "expr": "max by (namespace) (barman_cloud_cloudnative_pg_io_last_available_backup_timestamp{namespace=~\"$namespace\"} or cnpg_collector_last_available_backup_timestamp{namespace=~\"$namespace\"})",
"refId": "A", "refId": "A",
"editorMode": "code", "editorMode": "code",
"range": true, "range": true,