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
155
infrastructure/garage-linode/README.md
Normal file
155
infrastructure/garage-linode/README.md
Normal file
|
|
@ -0,0 +1,155 @@
|
|||
# Garage on the Linode — the CloudNativePG WAL archive
|
||||
|
||||
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
|
||||
integration for `sirius-growth/portal` (continuous WAL archiving + daily base
|
||||
backups → point-in-time recovery).
|
||||
|
||||
It is **not** the Pi's Garage (`infrastructure/garage/`, node
|
||||
`d053db4dfc97bf78`). Different host, different `node_key`, different metadata
|
||||
dir, no RPC peering, nothing shared. That is the whole point:
|
||||
|
||||
> The CNPG primary runs on `siriussec` in the same building, on the same power
|
||||
> domain and the same uplink as the Pi. A WAL archive on the Pi would be a second
|
||||
> copy of the same failure. The archive has to be off-site; the Linode is the
|
||||
> only off-site box in this estate.
|
||||
|
||||
## What runs
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
| Host | Linode VPS, Kubernetes node `linode`, WireGuard `10.10.0.5` (`dummy-k8s`), hub `10.20.0.1` on `wg0` |
|
||||
| Runtime | **podman 5.4** + a quadlet unit. This host is a kubelet node: installing `dockerd` next to the kubelet's containerd would add a second container runtime for no benefit, so the Pi's compose file cannot be reused verbatim |
|
||||
| Unit | `/etc/containers/systemd/garage.container` → generated `garage.service` (`Restart=always`) |
|
||||
| Image | `dxflrs/garage:v1.1.0` (same pinned tag as the Pi) |
|
||||
| Config | `/etc/garage/garage.toml` (installed from this directory) |
|
||||
| RPC secret | `/etc/garage/garage.env` → `GARAGE_RPC_SECRET`, `0600 root:root`, **not in git** |
|
||||
| State | `/var/lib/garage/meta` (metadata, `node_key`) and `/var/lib/garage/data` (objects) |
|
||||
| Node | `994fd2f42ae72da6`, zone `dc1`, capacity **20 GB**, `replication_factor = 1` |
|
||||
| Bucket | `pg-wal-archive` — private, `Website access: false` |
|
||||
|
||||
## Exposure — WireGuard only, twice
|
||||
|
||||
1. `garage.toml` binds `10.10.0.5:3900` (S3) and `10.10.0.5:3903` (admin/metrics)
|
||||
explicitly. There is no `0.0.0.0` listener and `eth0` (the public IP) is never
|
||||
bound, so `ss -ltn` is proof by itself.
|
||||
2. `host/wal-archive-firewall.nft` is an nftables table in **PREROUTING priority
|
||||
-140** that accepts 3900/3903 only from `lo`/`wg0` (plus source
|
||||
`10.244.0.0/16` for pods on this node) and **drops** everything else, with
|
||||
counters on every rule. podman with `Network=host` does not need DNAT, but
|
||||
the table keeps a future port mapping from reopening the path — and ufw alone
|
||||
would not cover a container publish, exactly as on the Pi.
|
||||
|
||||
Measured (2026-11-19), from the laptop **straight to the Linode's public IP with
|
||||
no VPN in the path**: 3900 and 3903 both `filtered`, and
|
||||
`nft list table inet wal_archive_guard` shows the drop counter incrementing.
|
||||
Anonymous `GET http://10.10.0.5:3900/pg-wal-archive/` → **403 AccessDenied**.
|
||||
|
||||
## Install / re-install
|
||||
|
||||
```bash
|
||||
# on the Linode, from a checkout of sirius/homek8s
|
||||
cd infrastructure/garage-linode
|
||||
sudo ./install.sh
|
||||
```
|
||||
|
||||
`install.sh` is idempotent: it installs podman if missing, writes
|
||||
`/etc/garage/{garage.toml,garage.env}` (generating the RPC secret once), installs
|
||||
the quadlet unit and the nft guard **before** starting the container, then
|
||||
assigns the layout capacity on first run (`layout assign -z dc1 -c 20G`) and
|
||||
prints `garage status` + the listener set.
|
||||
|
||||
Verify (all four must hold):
|
||||
|
||||
```bash
|
||||
systemctl status garage.service --no-pager | head -3
|
||||
ss -ltnH 'sport = :3900 or sport = :3903' # only 10.10.0.5, never 0.0.0.0
|
||||
podman exec garage /garage -c /etc/garage.toml status # node 994fd2f42ae72da6, HEALTHY
|
||||
nft list table inet wal_archive_guard # counters on accept and drop
|
||||
```
|
||||
|
||||
## Bucket and key
|
||||
|
||||
```bash
|
||||
G() { podman exec garage /garage -c /etc/garage.toml "$@"; }
|
||||
G bucket create pg-wal-archive
|
||||
G key create cnpg-portal-wal # prints the secret once — capture it
|
||||
G bucket allow --read --write pg-wal-archive --key cnpg-portal-wal
|
||||
G bucket info pg-wal-archive # Website access: false
|
||||
```
|
||||
|
||||
Key ID `GK7f2b4bb1fc9abaec50fde37b` (`cnpg-portal-wal`), scope **read+write on
|
||||
`pg-wal-archive` only** — no bucket-create, no other bucket, not an admin key.
|
||||
The secret lives in the cluster as Secret `sirius-growth/portal-wal-s3`
|
||||
(`ACCESS_KEY_ID`, `ACCESS_SECRET_KEY`, `REGION=garage`), created out of band and
|
||||
**never committed**. Garage v1.1 has no `--yes` on `key create`; the secret is
|
||||
printed exactly once, so redirect it to a `0600` root file and read it from there.
|
||||
|
||||
## Disk sizing and retention
|
||||
|
||||
Measured 2026-11-19:
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
| Linode `/` | 79 GB, 29 GB used, **46 GB free** |
|
||||
| Garage capacity | **20 GB** (layout), i.e. the store stops accepting before the disk does |
|
||||
| First base backup + 7 WAL segments | **4.9 MB** in 8 bucket objects (`/var/lib/garage/data` 9.3 MB including Garage's block-store overhead, `meta` 4.6 MB) |
|
||||
| `archive_timeout` / `wal_segment_size` on the primary | 5 min / 16 MB → at most 288 segments/day |
|
||||
| Observed compressed segment | 16–25 KB when the portal is quiet |
|
||||
| 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 |
|
||||
|
||||
Retention is `spec.backup.retentionPolicy: "14d"` on the Cluster, enforced by
|
||||
barman-cloud when a backup completes. The 20 GB cap is deliberate: when it is
|
||||
reached Garage returns `507 InsufficientStorage` and the `Backup` /
|
||||
`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
|
||||
Linode disk; never to delete WALs by hand (that breaks the archive's
|
||||
continuity and every PITR target that depends on the deleted segment).
|
||||
|
||||
## How the archive is laid out
|
||||
|
||||
`destinationPath: s3://pg-wal-archive` (bucket root) with the barman server name
|
||||
defaulting to the cluster name, so:
|
||||
|
||||
```
|
||||
pg-wal-archive/portal/base/20261119T223452/{backup.info,data.tar.gz}
|
||||
pg-wal-archive/portal/wals/0000000100000000/00000001000000000000005A.gz
|
||||
```
|
||||
|
||||
That is one prefix per cluster, which is what lets `forgejo/pg` share this bucket
|
||||
later without colliding. Listing it (the postgres container has no credentials in
|
||||
its own environment; the Secret does):
|
||||
|
||||
```bash
|
||||
kubectl -n sirius-growth run wal-list --rm -it --restart=Never \
|
||||
--image=public.ecr.aws/aws-cli/aws-cli:2.15.30 \
|
||||
--overrides='{"spec":{"containers":[{"name":"aws","image":"public.ecr.aws/aws-cli/aws-cli:2.15.30",
|
||||
"envFrom":[{"secretRef":{"name":"portal-wal-s3"}}],
|
||||
"command":["sh","-c","export AWS_ACCESS_KEY_ID=$ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY=$ACCESS_SECRET_KEY AWS_DEFAULT_REGION=$REGION; aws --endpoint-url http://10.10.0.5:3900 s3 ls --recursive --human-readable s3://pg-wal-archive/"]}]}}'
|
||||
```
|
||||
|
||||
## Restore
|
||||
|
||||
Point-in-time recovery is a **cluster restore**, not a file copy. The full
|
||||
rehearsed recipe (marker → restore to `targetTime` → verify) is §8.3 of
|
||||
`docs/cluster-overview.md`; `pitr-restore.md` in this directory is the
|
||||
self-contained version with the commands and the acceptance output.
|
||||
|
||||
Short form: a throwaway `Cluster` with `bootstrap.recovery.source` pointing at an
|
||||
`externalClusters` entry (`serverName: portal`, the same bucket and Secret) and
|
||||
`recoveryTarget.targetTime`, then promote/cut over. Recovery needs the **base
|
||||
backup** plus every WAL segment up to the target — one missing segment is a
|
||||
failed restore, which is why the archive is never pruned by hand.
|
||||
|
||||
## What this store is *not*
|
||||
|
||||
- **Not a cluster peer of the Pi's Garage.** No `[rpc]` peering, no shared
|
||||
`rpc_secret`, no replicated data. Two independent single-node stores.
|
||||
- **Not Flux-managed.** Flux watches `./clusters/homek8s`; nothing there
|
||||
references this directory. A push changes nothing on the Linode until
|
||||
`install.sh` runs.
|
||||
- **Not a general-purpose bucket host.** One bucket, one key, one consumer. Put
|
||||
application media on the Pi's store; this one exists to be off-site.
|
||||
- **Not exposed to the LAN or the internet**, and no Cloudflare tunnel, DNS
|
||||
record or public bucket will be added to it.
|
||||
38
infrastructure/garage-linode/garage.container
Normal file
38
infrastructure/garage-linode/garage.container
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
# Quadlet unit — Garage WAL archive on the Linode hub (10.10.0.5).
|
||||
#
|
||||
# Installed to /etc/containers/systemd/garage.container by install.sh; the
|
||||
# podman systemd generator turns it into `garage.service` on the next
|
||||
# `systemctl daemon-reload`. There is no docker on this host (it is a kubelet
|
||||
# node — installing dockerd here would add a second container runtime next to
|
||||
# the kubelet's containerd for no reason), so the Pi's compose file cannot be
|
||||
# reused verbatim. Quadlet is the podman-native equivalent: one declarative
|
||||
# file, systemd owns the lifecycle, no daemon of its own.
|
||||
#
|
||||
# Network=host on purpose: the container binds 10.10.0.5:3900 from garage.toml
|
||||
# directly, so the published addresses are visible in `ss -lnt` on the host and
|
||||
# no podman port-forwarding rules are injected into the node's netfilter state.
|
||||
|
||||
[Unit]
|
||||
Description=Garage S3 — CloudNativePG WAL archive (WireGuard-only)
|
||||
Documentation=file:///etc/garage/README.md
|
||||
After=network-online.target
|
||||
Wants=network-online.target
|
||||
|
||||
[Container]
|
||||
ContainerName=garage
|
||||
Image=docker.io/dxflrs/garage:v1.1.0
|
||||
Network=host
|
||||
EnvironmentFile=/etc/garage/garage.env
|
||||
Volume=/etc/garage/garage.toml:/etc/garage.toml:ro
|
||||
Volume=/var/lib/garage/meta:/data/meta
|
||||
Volume=/var/lib/garage/data:/data/data
|
||||
Exec=/garage -c /etc/garage.toml server
|
||||
LogDriver=journald
|
||||
|
||||
[Service]
|
||||
Restart=always
|
||||
TimeoutStartSec=120
|
||||
TimeoutStopSec=60
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
47
infrastructure/garage-linode/garage.toml
Normal file
47
infrastructure/garage-linode/garage.toml
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
# Garage v1.1.0 — WAL archive for CloudNativePG, on the Linode hub.
|
||||
#
|
||||
# Installed to /etc/garage/garage.toml (root:root 0644) by install.sh.
|
||||
#
|
||||
# This is a SECOND, independent Garage node — not a cluster peer of the Pi's
|
||||
# node `d053db4dfc97bf78`. It exists because a WAL archive must live off-site:
|
||||
# the Pi and the CNPG primary (siriussec) share a building, power domain and
|
||||
# internet uplink, so archiving WALs there is a second copy of the same
|
||||
# failure. Different node_key, different metadata dir, `replication_factor = 1`,
|
||||
# nothing shared with the Pi's store.
|
||||
#
|
||||
# Listeners are bound to explicit addresses here AND the ports are guarded by
|
||||
# host/wal-archive-firewall.nft before Docker-style DNAT could ever matter.
|
||||
# `10.10.0.5` is the Linode worker's WireGuard-mesh InternalIP (dummy-k8s) —
|
||||
# the only address any cluster pod can reach this on. eth0 (50.116.38.217) is
|
||||
# not bound at all, so an off-mesh scan sees a filtered port, not a listener.
|
||||
#
|
||||
# rpc_secret is NOT in this file: GARAGE_RPC_SECRET comes from
|
||||
# /etc/garage/garage.env (0600, out of git), same as the Pi's node.
|
||||
|
||||
metadata_dir = "/data/meta"
|
||||
data_dir = "/data/data"
|
||||
db_engine = "sqlite"
|
||||
replication_factor = 1
|
||||
|
||||
# Single node: nothing outside the container speaks RPC. Garage still needs the
|
||||
# listener for its own CLI-over-loopback calls (`garage status`, `garage key`).
|
||||
rpc_bind_addr = "127.0.0.1:3901"
|
||||
rpc_public_addr = "127.0.0.1:3901"
|
||||
|
||||
[s3_api]
|
||||
s3_region = "garage"
|
||||
# WireGuard address only. An empty/i.e. 0.0.0.0 bind here would put barman's
|
||||
# archive on the Linode's public interface.
|
||||
api_bind_addr = "10.10.0.5:3900"
|
||||
|
||||
# Admin API + Prometheus metrics, mesh-only. No metrics_token: the port does not
|
||||
# leave the WireGuard mesh. Add one here (and a bearer token in the scrape
|
||||
# config) if 3903 is ever exposed beyond it. Not scraped today — the archive's
|
||||
# growth is asserted from the filesystem in the backup README instead.
|
||||
[admin]
|
||||
api_bind_addr = "10.10.0.5:3903"
|
||||
|
||||
# node_key is generated on first start and lives in metadata_dir (/data/meta).
|
||||
# It is part of /root/garage-backup for the Pi's node; this node's meta/ is
|
||||
# covered by the cluster-backup mirror on the same host. Restore meta/ before
|
||||
# data/ or the layout no longer names this node and every bucket is orphaned.
|
||||
20
infrastructure/garage-linode/host/install-wal-archive-firewall.sh
Executable file
20
infrastructure/garage-linode/host/install-wal-archive-firewall.sh
Executable file
|
|
@ -0,0 +1,20 @@
|
|||
#!/usr/bin/env bash
|
||||
# Install the WAL-archive inbound guard on the Linode hub. Idempotent.
|
||||
#
|
||||
# sudo ./install-wal-archive-firewall.sh
|
||||
#
|
||||
# Verifies the table afterwards instead of trusting `systemctl start`'s exit 0.
|
||||
set -euo pipefail
|
||||
|
||||
here=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||
|
||||
install -D -m 0644 "$here/wal-archive-firewall.nft" /etc/nftables.d/wal_archive_guard.nft
|
||||
install -D -m 0644 "$here/wal-archive-firewall.service" /etc/systemd/system/wal-archive-firewall.service
|
||||
|
||||
systemctl daemon-reload
|
||||
systemctl enable --now wal-archive-firewall.service
|
||||
|
||||
nft list table inet wal_archive_guard >/dev/null
|
||||
nft list table inet wal_archive_guard | grep -q 'dport { 3900, 3903 }'
|
||||
echo "OK: wal_archive_guard loaded"
|
||||
nft list table inet wal_archive_guard
|
||||
41
infrastructure/garage-linode/host/wal-archive-firewall.nft
Normal file
41
infrastructure/garage-linode/host/wal-archive-firewall.nft
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
#!/usr/sbin/nft -f
|
||||
# WAL-archive inbound guard — defence in depth for Garage on the Linode hub.
|
||||
#
|
||||
# WHY THIS EXISTS AND WHY UFW ALONE IS NOT ENOUGH:
|
||||
# On the Pi the risk is docker's DNAT bypassing ufw's INPUT chain. Here the
|
||||
# store runs under podman with Network=host, so there is no DNAT to bypass —
|
||||
# but the same rule shape is kept anyway, because the next person who adds a
|
||||
# port mapping (or a second container that proxies this one) must not be able
|
||||
# to reach 3900 from eth0 by accident. This table is evaluated in PREROUTING
|
||||
# at priority -140, before any DNAT, so it binds the exposure to the transport
|
||||
# rather than to how the listener was published.
|
||||
#
|
||||
# Effective policy for 3900 (S3 API) and 3903 (metrics/admin):
|
||||
# accept from WireGuard (wg0) and loopback — incl. pod traffic arriving from
|
||||
# the mesh with a 10.244.x source — drop everything else (eth0, LAN, public).
|
||||
# DROP not REJECT: an off-mesh scan sees `filtered` and learns nothing.
|
||||
#
|
||||
# Note this is *in addition to* ufw, which on this host allows 22 from
|
||||
# 10.20.0.0/24 and any from 10.10.0.0/24 / 10.244.0.0/16. ufw's own default is
|
||||
# deny incoming, so the LAN path is already closed; this table keeps it closed
|
||||
# even if someone later opens ufw wider for a different service.
|
||||
#
|
||||
# `destroy` (not `delete`) so re-running the unit replaces the table instead of
|
||||
# appending a duplicate, and does not fail on first install.
|
||||
|
||||
destroy table inet wal_archive_guard
|
||||
table inet wal_archive_guard {
|
||||
chain prerouting {
|
||||
type filter hook prerouting priority -140; policy accept;
|
||||
|
||||
# WireGuard mesh + hub link, and loopback (the garage CLI talks to
|
||||
# 127.0.0.1:3901 inside this host namespace).
|
||||
iifname { "lo", "wg0" } tcp dport { 3900, 3903 } counter accept
|
||||
|
||||
# Pods on this node reach the dummy-k8s address from the pod network.
|
||||
ip saddr 10.244.0.0/16 tcp dport { 3900, 3903 } counter accept
|
||||
|
||||
# Everything else — eth0/public, any future interface nobody added above.
|
||||
tcp dport { 3900, 3903 } counter drop
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
# /etc/systemd/system/wal-archive-firewall.service (linode)
|
||||
#
|
||||
# Host unit, installed by hand (not Flux-managed) — the file lives in git at
|
||||
# infrastructure/garage-linode/host/. Same shape as garage-firewall.service on
|
||||
# the Pi and k8s-api-firewall.service on siriussec.
|
||||
#
|
||||
# No Requires= on wg-quick@wg0: the tunnel is enabled at boot on this host but a
|
||||
# hard dependency would turn a transient tunnel failure into "store unguarded
|
||||
# and unit failed". The table only filters; it can load before the interface
|
||||
# exists.
|
||||
[Unit]
|
||||
Description=Drop off-WireGuard inbound to the Garage WAL archive (3900/3903)
|
||||
After=network-online.target
|
||||
Wants=network-online.target
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/sbin/nft -f /etc/nftables.d/wal_archive_guard.nft
|
||||
RemainAfterExit=yes
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
60
infrastructure/garage-linode/install.sh
Executable file
60
infrastructure/garage-linode/install.sh
Executable file
|
|
@ -0,0 +1,60 @@
|
|||
#!/usr/bin/env bash
|
||||
# Install the Garage WAL archive on the Linode hub (10.10.0.5). Idempotent.
|
||||
#
|
||||
# sudo ./install.sh
|
||||
#
|
||||
# Installs: podman (if missing), /etc/garage/{garage.toml,garage.env},
|
||||
# /etc/containers/systemd/garage.container, the nft guard, and the state dirs.
|
||||
# Then starts the unit and assigns the node's layout capacity on first run.
|
||||
#
|
||||
# The RPC secret is generated once and never printed. Rewriting it on an
|
||||
# existing install is harmless for a single-node store, but the copy in
|
||||
# /root/garage-backup is what a rebuild should reuse.
|
||||
set -euo pipefail
|
||||
|
||||
here=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||
|
||||
command -v podman >/dev/null || {
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
apt-get update -qq
|
||||
apt-get install -y podman
|
||||
}
|
||||
|
||||
install -d -m 0755 /etc/garage /etc/containers/systemd /etc/nftables.d
|
||||
install -d -m 0700 /var/lib/garage/meta /var/lib/garage/data
|
||||
|
||||
install -m 0644 "$here/garage.toml" /etc/garage/garage.toml
|
||||
install -m 0644 "$here/garage.container" /etc/containers/systemd/garage.container
|
||||
|
||||
if [ ! -s /etc/garage/garage.env ]; then
|
||||
umask 077
|
||||
printf 'GARAGE_RPC_SECRET=%s\n' "$(openssl rand -hex 32)" > /etc/garage/garage.env
|
||||
fi
|
||||
chmod 0600 /etc/garage/garage.env
|
||||
|
||||
# Guard first: the listener must never exist unguarded, not even for the
|
||||
# seconds between `compose/quadlet up` and a firewall install.
|
||||
"$here/host/install-wal-archive-firewall.sh" >/dev/null
|
||||
|
||||
systemctl daemon-reload
|
||||
systemctl start garage.service
|
||||
|
||||
# First run only: this Garage node needs a layout entry before it accepts
|
||||
# writes. Capacity 20 GB against a 79 GB disk holding 29 GB of other data —
|
||||
# see README "Disk sizing".
|
||||
for _ in $(seq 1 30); do
|
||||
garage_status=$(podman exec garage /garage -c /etc/garage.toml status 2>&1 || true)
|
||||
grep -q 'NO ROLE' <<<"$garage_status" && break
|
||||
sleep 2
|
||||
done
|
||||
|
||||
if grep -q 'NO ROLE' <<<"$garage_status"; then
|
||||
node_id=$(awk '/NO ROLE/{print $1}' <<<"$garage_status" | head -1)
|
||||
podman exec garage /garage -c /etc/garage.toml layout assign -z dc1 -c 20G "$node_id"
|
||||
podman exec garage /garage -c /etc/garage.toml layout apply --version 1
|
||||
fi
|
||||
|
||||
# Verify rather than assume.
|
||||
podman exec garage /garage -c /etc/garage.toml status
|
||||
ss -ltnH 'sport = :3900 or sport = :3903'
|
||||
nft list table inet wal_archive_guard >/dev/null && echo "OK: wal_archive_guard loaded"
|
||||
177
infrastructure/garage-linode/pitr-restore.md
Normal file
177
infrastructure/garage-linode/pitr-restore.md
Normal file
|
|
@ -0,0 +1,177 @@
|
|||
# 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
|
||||
archive. This file records the commands and the actual output of that 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`
|
||||
over the WireGuard mesh, credentials in Secret `sirius-growth/portal-wal-s3`.
|
||||
Producer: `spec.backup.barmanObjectStore` on `Cluster sirius-growth/portal`
|
||||
(WAL archiving continuous, `ScheduledBackup portal-daily` at 03:20 UTC,
|
||||
`retentionPolicy: 14d`).
|
||||
|
||||
## 0. Is the archive actually healthy?
|
||||
|
||||
```bash
|
||||
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"
|
||||
# 00000001000000000000005B|2026-11-19 22:40:30.1+00|0
|
||||
```
|
||||
|
||||
`failed_count` must be 0 and `last_archived_time` must be minutes old. A
|
||||
`targetTime` after the last archived WAL cannot be reached — recovery stops at
|
||||
the last segment it can fetch.
|
||||
|
||||
```bash
|
||||
kubectl -n sirius-growth get backup -o wide # newest barmanObjectStore Backup: completed
|
||||
kubectl -n sirius-growth get scheduledbackup # portal-daily, LAST BACKUP set
|
||||
```
|
||||
|
||||
## 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
|
||||
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"
|
||||
# 3|2026-11-19 22:35:06.127778+00
|
||||
q "select pg_switch_wal()" ; sleep 12
|
||||
q "select last_archived_wal, last_archived_time from pg_stat_archiver"
|
||||
# 000000010000000000000059|2026-11-19 22:35:07.089783+00
|
||||
sleep 10
|
||||
q "insert into pitr_probe(note) values ('POISON-after-target') returning id, at"
|
||||
# 4|2026-11-19 22:35:28.959782+00
|
||||
q "select pg_switch_wal()" ; sleep 12
|
||||
q "select last_archived_wal, last_archived_time from pg_stat_archiver"
|
||||
# 00000001000000000000005A|2026-11-19 22:35:29.906592+00
|
||||
```
|
||||
|
||||
The target is therefore **`2026-11-19T22:35:15Z`** — 9 s after the marker, 14 s
|
||||
before the row that must be lost. Note that WAL `…05A` (which contains the poison
|
||||
row) *is* in the archive: the restore has to choose to stop, it is not starved of
|
||||
data.
|
||||
|
||||
## 2. Restore into a throwaway cluster
|
||||
|
||||
Never restore over the live `portal` cluster while it is serving.
|
||||
|
||||
```yaml
|
||||
apiVersion: postgresql.cnpg.io/v1
|
||||
kind: Cluster
|
||||
metadata:
|
||||
name: portal-pitr-test
|
||||
namespace: sirius-growth
|
||||
labels: {purpose: pitr-acceptance-test}
|
||||
spec:
|
||||
instances: 1
|
||||
imageName: ghcr.io/cloudnative-pg/postgresql:16
|
||||
storage: {size: 5Gi, storageClass: local-path}
|
||||
affinity: {nodeSelector: {kubernetes.io/hostname: siriussec}}
|
||||
resources:
|
||||
requests: {cpu: 100m, memory: 256Mi}
|
||||
limits: {memory: 1Gi}
|
||||
bootstrap:
|
||||
recovery:
|
||||
source: portal-wal
|
||||
recoveryTarget:
|
||||
targetTime: "2026-11-19T22:35:15Z"
|
||||
externalClusters:
|
||||
- name: portal-wal
|
||||
barmanObjectStore:
|
||||
destinationPath: s3://pg-wal-archive
|
||||
endpointURL: http://10.10.0.5:3900
|
||||
serverName: portal # MUST match 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}
|
||||
```
|
||||
|
||||
`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
|
||||
an empty history. `targetTime` is UTC RFC3339 — a wrong timezone silently
|
||||
restores the wrong hour.
|
||||
|
||||
The operator restores the base backup, replays WAL, stops at the target and
|
||||
promotes:
|
||||
|
||||
```
|
||||
ready=False phase=Setting up primary
|
||||
ready=False phase=Waiting for the instances to become active
|
||||
ready=True phase=Cluster in healthy state
|
||||
portal-pitr-test 1 1 Cluster in healthy state portal-pitr-test-1
|
||||
```
|
||||
|
||||
## 3. The acceptance evidence
|
||||
|
||||
```
|
||||
$ 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
|
||||
```
|
||||
|
||||
Marker present, post-target row gone. The rest of the database came back with it
|
||||
(physical restore, all databases, no `pg_restore` ordering games), e.g.
|
||||
`clients 4 = 4`, `calendar_tokens 3 = 3`, `applications 1 = 1` against the
|
||||
primary at that moment.
|
||||
|
||||
```
|
||||
$ ... -tAc "select pg_is_in_recovery()"
|
||||
f # replay finished, instance promoted
|
||||
```
|
||||
|
||||
`pg_is_in_recovery() = f` is expected here and is **not** a failure: a CNPG
|
||||
recovery cluster with `instances: 1` promotes itself once it hits the target. It
|
||||
is writable from that moment — which is why the test cluster must be deleted, and
|
||||
why nothing may point application traffic at it before you decide to.
|
||||
|
||||
```bash
|
||||
kubectl -n sirius-growth delete cluster portal-pitr-test
|
||||
```
|
||||
|
||||
## 4. Making the restored data the real data
|
||||
|
||||
Two shapes, both legitimate:
|
||||
|
||||
1. **Cut over (preferred, reversible).** Point the app at
|
||||
`portal-pitr-test-rw` (`POSTGRES_HOST` in the API/portal Deployments — through
|
||||
git, not `kubectl set env`), verify, then drop the old cluster only after the
|
||||
app has been confirmed on the restored copy.
|
||||
2. **In place.** Keep `portal`, stop its instances, and swap the PVC content from
|
||||
the recovered data directory. Slower, destructive, and easy to get wrong —
|
||||
only with the app scaled to zero.
|
||||
|
||||
Either way, take a fresh base backup once the decision is made
|
||||
(`kubectl apply` a `Backup` CR against the surviving cluster) so the archive has
|
||||
a post-recovery base rather than one from before the incident.
|
||||
|
||||
## Gotchas that cost time
|
||||
|
||||
- **Flux owns `apps/base/sirius-growth/cluster.yaml`.** A hand `kubectl apply` of
|
||||
a new `spec.backup` is reverted by the `apps` Kustomization within its 1 min
|
||||
interval. Config changes belong in the branch/PR. (During the rehearsal the
|
||||
`kustomize-controller` Deployment was scaled to 0 for the test window and
|
||||
scaled back afterwards; `Backup`/`Cluster` objects created by hand are not in
|
||||
the Kustomization inventory, so they are not pruned.)
|
||||
- **`ScheduledBackup.spec.schedule` is six-field cron, seconds first.** `0 20 3
|
||||
* * *` = 03:20:00 UTC. Copying a five-field crontab string silently means
|
||||
"every minute" in the first field.
|
||||
- **The bucket prefix is `portal/portal/…` only if you get `destinationPath`
|
||||
wrong.** Use `s3://pg-wal-archive` for the bucket root; barman appends the
|
||||
server name.
|
||||
- **CNPG 1.30 warns that in-tree barman-cloud is removed in 1.31.** If that
|
||||
upgrade happens, migrate to the Barman Cloud Plugin first; until then the
|
||||
archives remain readable by `barman-cloud-restore` in the same container image.
|
||||
- **If archiving has failed** (`pg_stat_archiver.failed_count > 0`), 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
|
||||
`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
|
||||
barman and of the Linode Garage node.
|
||||
Loading…
Reference in a new issue