homek8s/infrastructure/wireguard/backup/README.md
Lance Walters c1fe485469 apps(backup): cover the remaining stateful gaps off-host
Four pieces of state were still only on the machine they run on. All four now
land on the Linode over the WireGuard mesh, in the same /root/cluster-backup
tree (or /root/pihost-backup for the Pi) with the same manifest/sha256 habit:

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

Each tree carries its own retention, so adding artifacts cannot crowd the
Linode. Docs §8/§8.1/§8.2 record coverage, the accepted gaps (Prometheus TSDB,
camera frames, runner scratch) and the restore procedure — including the
TimescaleDB pre/post-restore calls osint needs.
2026-11-19 17:14:36 -05:00

3.7 KiB

WireGuard hub state — backup of /etc/wireguard + the wgportal peer database

The Pi (rpi, 10.10.0.1) is the WireGuard hub of the mesh and a spoke of the Linode hub (10.20.0.1). Two files there are unrebuildable:

Path What it is
/etc/wireguard/wg0.conf wgportal-autogenerated hub config: wg0 server key, every peer, every AllowedIPs
/etc/wireguard/wg-remote.conf the Pi→Linode spoke (key + endpoint)
/opt/wgportal/data/sqlite.db wgportal's peer database (identifiers, keys, allowed IPs, display names)

A rebuilt Pi comes back from git + Garage's own backup — but the peer set and the hub key would be gone, and with them every remote-access path. This directory mirrors infrastructure/garage/backup/: a small script plus a systemd timer that copies the state off the Pi to [email protected]:/root/pihost-backup/.

This directory is NOT applied by Flux

Flux only reconciles ./clusters/homek8s. Install these by hand (they are host units, not cluster objects):

# from the repo checkout on the Pi (or scp the three files over)
sudo install -m 0755 wireguard-backup.sh /usr/local/sbin/wireguard-backup.sh
sudo install -m 0644 wireguard-backup.service wireguard-backup.timer /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable --now wireguard-backup.timer

# one hand-fired run, and read the result (exit code is the truth)
sudo systemctl start wireguard-backup.service
systemctl status wireguard-backup.service --no-pager
journalctl -u wireguard-backup.service -n 40 --no-pager

Re-run the install after a Pi reinstall — the units do not survive a reimage.

What lands on the Linode

/root/pihost-backup/wireguard/wireguard-<UTC stamp>.tar.gz   mode 0600
/root/pihost-backup/manifests/<stamp>.txt                    sizes + sha256
  • One tarball per run (/etc/wireguard/ verbatim, including the .bak peer history, plus wgportal-sqlite.db). Retention: 14 tarballs + 14 manifests, enforced by the script.
  • The sqlite copy is taken with the sqlite backup API (python3 stdlib — there is no sqlite3 CLI on the Pi), not cp: a live cp can capture a half-written page. The script runs PRAGMA integrity_check on the copy and fails the unit if it is not ok.
  • The tarball is checksummed on both sides before the .part file is renamed.
  • Transport is the wg-remote tunnel using the existing sirius user key (/home/sirius/.ssh/linode_admin). Never the Linode public IP.

Restore

The tarball contains private keys — treat it as a secret, not an archive.

# pull the newest tarball and inspect it WITHOUT writing to /etc
ssh -i /home/sirius/.ssh/linode_admin [email protected] \
  'ls -1t /root/pihost-backup/wireguard/*.tar.gz | head -1' # pick a stamp
ssh -i /home/sirius/.ssh/linode_admin [email protected] \
  'cat /root/pihost-backup/wireguard/wireguard-<stamp>.tar.gz' \
  | tar -tzf -

# restore onto a rebuilt Pi (stop the interfaces first so a running wg-quick
# does not rewrite wg0.conf with SaveConfig = true)
sudo systemctl stop wg-quick@wg-remote || true
sudo wg-quick down wg0 || true
ssh ... 'cat /root/pihost-backup/wireguard/wireguard-<stamp>.tar.gz' | sudo tar -xzf - -C /
sudo install -m 0600 -o root -g root /dev/null /dev/null   # no-op, permissions come from the archive
sudo systemctl start wg-quick@wg0 && sudo systemctl start wg-quick@wg-remote
sudo wg show

If only wgportal lost its database: extract wgportal-sqlite.db from the tarball, run PRAGMA integrity_check on it, and copy it over /opt/wgportal/data/sqlite.db while the wgportal container is stopped — a portal restart rewrites peers from live wg set state, so stop/start it deliberately rather than leaving it running mid-restore.