# 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 `root@10.20.0.1:/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): ```bash # 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-.tar.gz mode 0600 /root/pihost-backup/manifests/.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. ```bash # pull the newest tarball and inspect it WITHOUT writing to /etc ssh -i /home/sirius/.ssh/linode_admin root@10.20.0.1 \ 'ls -1t /root/pihost-backup/wireguard/*.tar.gz | head -1' # pick a stamp ssh -i /home/sirius/.ssh/linode_admin root@10.20.0.1 \ 'cat /root/pihost-backup/wireguard/wireguard-.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-.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.