How are backups taken, and how do we recover from disaster? #70

Closed
opened 2026-11-27 14:38:42 -05:00 by bobby · 1 comment
Owner

Part of #44

Question

What is the v1 backup and disaster-recovery plan: the off-platform pg_dump (schedule, target, encryption, retention), the restore-to-new-cluster runbook (shared with plan resizes) and how often it's rehearsed, rebuilding the cluster from code, and what in-cluster state (e.g. the 1-year breakglass audit) needs its own backup?

Context carried from the map: managed-DB backups and restore drills, cluster rebuild from code, in-cluster state. A restore forks a new DB cluster (new host), so rerun hapi db bootstrap and repoint the app. Our own off-platform pg_dump covers account loss and >14-day retention (see ADR-0004). Resizing the DB plan uses the same restore-to-new-cluster runbook, so one rehearsal covers both. The backup target's credentials and the dump encryption key each follow ADR-0008 (one narrow token, delivered through SOPS). A cluster rebuild needs the age key from Vaultwarden or the offline copy. The pg_dump job should report to a Kuma push monitor ("no successful backup in 26 h"), as ADR-0009 does with its Watchdog. The monitoring PVs hold only rebuildable or expendable data, except the 1-year breakglass audit events.

From How do scheduled and background jobs run? (ADR-0012): recurring work runs as CronJobs of the hAPI image with concurrencyPolicy: Forbid. Every CronJob is covered by a generic vmalert staleness rule, and Kuma push is reserved for jobs (like backups) whose silence must be caught even if the cluster is down. A pg_dump CronJob uses connections from ADR-0004's amended budget.

Part of #44 ## Question What is the v1 backup and disaster-recovery plan: the off-platform `pg_dump` (schedule, target, encryption, retention), the restore-to-new-cluster runbook (shared with plan resizes) and how often it's rehearsed, rebuilding the cluster from code, and what in-cluster state (e.g. the 1-year breakglass audit) needs its own backup? **Context carried from the map:** managed-DB backups and restore drills, cluster rebuild from code, in-cluster state. A restore forks a **new** DB cluster (new host), so rerun `hapi db bootstrap` and repoint the app. Our own off-platform `pg_dump` covers account loss and >14-day retention (see ADR-0004). Resizing the DB plan uses the same restore-to-new-cluster runbook, so one rehearsal covers both. The backup target's credentials and the dump encryption key each follow ADR-0008 (one narrow token, delivered through SOPS). A cluster rebuild needs the age key from Vaultwarden or the offline copy. The `pg_dump` job should report to a Kuma push monitor ("no successful backup in 26 h"), as ADR-0009 does with its Watchdog. The monitoring PVs hold only rebuildable or expendable data, except the 1-year breakglass audit events. **From *How do scheduled and background jobs run?* (ADR-0012):** recurring work runs as CronJobs of the hAPI image with `concurrencyPolicy: Forbid`. Every CronJob is covered by a generic vmalert staleness rule, and Kuma push is reserved for jobs (like backups) whose silence must be caught even if the cluster is down. A `pg_dump` CronJob uses connections from ADR-0004's amended budget.
bobby added the wayfinder:grilling label 2026-11-27 14:38:42 -05:00
bobby added a new dependency 2026-11-27 14:38:51 -05:00
bobby self-assigned this 2026-11-27 15:21:01 -05:00
Author
Owner

Resolution

Recorded in ADR-0014. It amends ADR-0004 (the hapi_backup role) and ADR-0009 (breakglass audit events now survive a rebuild).

  • Three disaster tiers and how much each may lose: (a) inside Linode: point-in-time restore, minutes of data, back within ~2 h; (b) damage found after more than 14 days: our own dump, ≤1 day; (c) Linode account lost: rebuild from code plus the off-account copy, a weekend of downtime is fine. Nothing is highly available.
  • hapi db backup CronJob (hAPI image plus postgresql-client-18), daily at 03:00 Household time. It streams pg_dump -Fc → pg_restore --list check → age → upload, and the plaintext never touches disk. It runs as a new hapi_backup role (LOGIN, BYPASSRLS, SELECT only, created by bootstrap) using 1 connection.
  • A dedicated backup age keypair: the cluster has only the public recipient. The private key lives only in Vaultwarden and the offline copy, so a compromised cluster can't read old dumps.
  • Bucket hapi-backups in Linode Object Storage, with Object Lock in compliance mode, a 35-day lock and 35-day expiry. The cluster's key is read_write, limited to this bucket.
  • Off-account puller: infra/backup-pull/, rclone copy --immutable, with a read_only key. It keeps 90 dailies, monthlies for 3 years, audit/ for 1 year, and also pulls the versioned Tofu state bucket. For now it runs on the Owner's PC as a systemd user timer (Persistent=true) and moves to a NAS later. It isn't a Principal.
  • Breakglass audit: the backup job also exports the previous day's events from VictoriaLogs to audit/.
  • No etcd snapshots: the cluster is rebuilt from code. Gitea backups are out of scope; the fallbacks are the local clone and rebuilding images in CI.
  • Monitoring: Kuma push monitors for the backup job (26 h) and the puller (8 days while on the PC; change to 26 h when it moves to the NAS), plus ADR-0012's vmalert rule.
  • Restores run as hapi db restore in a pod, with the private key pasted in at run time. Path (A) is a point-in-time fork; path (B) restores our dump into a new database. Both go through bootstrap and then repoint the app.
  • Rehearsal: one full drill before go-live (cluster rebuilt from code in an empty project, then path B). After that, path B into a throwaway database every 6 months, tracked as a Household Maintenance Task "Rehearse disaster recovery".
  • To verify during the build: that akmadmin can create a BYPASSRLS role on Aiven, and that a limited read_write key can't delete a locked version.
## Resolution Recorded in [ADR-0014](https://git.bobbypalko.com/bobby/hapi/src/branch/main/docs/adr/0014-backups-and-disaster-recovery.md). It amends ADR-0004 (the `hapi_backup` role) and ADR-0009 (breakglass audit events now survive a rebuild). - **Three disaster tiers** and how much each may lose: (a) inside Linode: point-in-time restore, minutes of data, back within ~2 h; (b) damage found after more than 14 days: our own dump, ≤1 day; (c) Linode account lost: rebuild from code plus the off-account copy, a weekend of downtime is fine. Nothing is highly available. - **`hapi db backup` CronJob** (hAPI image plus `postgresql-client-18`), daily at 03:00 Household time. It streams `pg_dump -Fc` → `pg_restore --list` check → **age** → upload, and the plaintext never touches disk. It runs as a new **`hapi_backup`** role (LOGIN, `BYPASSRLS`, SELECT only, created by bootstrap) using 1 connection. - **A dedicated backup age keypair:** the cluster has only the public recipient. The private key lives only in Vaultwarden and the offline copy, so a compromised cluster can't read old dumps. - **Bucket `hapi-backups`** in Linode Object Storage, with **Object Lock in compliance mode**, a 35-day lock and 35-day expiry. The cluster's key is `read_write`, limited to this bucket. - **Off-account puller:** `infra/backup-pull/`, `rclone copy --immutable`, with a `read_only` key. It keeps 90 dailies, monthlies for 3 years, `audit/` for 1 year, and also pulls the versioned Tofu state bucket. **For now it runs on the Owner's PC** as a systemd user timer (`Persistent=true`) and moves to a NAS later. It isn't a Principal. - **Breakglass audit:** the backup job also exports the previous day's events from VictoriaLogs to `audit/`. - **No etcd snapshots:** the cluster is rebuilt from code. **Gitea backups are out of scope**; the fallbacks are the local clone and rebuilding images in CI. - **Monitoring:** Kuma push monitors for the backup job (26 h) and the puller (**8 days while on the PC; change to 26 h when it moves to the NAS**), plus ADR-0012's vmalert rule. - **Restores run as `hapi db restore` in a pod**, with the private key pasted in at run time. Path (A) is a point-in-time fork; path (B) restores our dump into a new database. Both go through bootstrap and then repoint the app. - **Rehearsal:** one full drill before go-live (cluster rebuilt from code in an empty project, then path B). After that, path B into a throwaway database every 6 months, tracked as a Household Maintenance Task "Rehearse disaster recovery". - **To verify during the build:** that `akmadmin` can create a `BYPASSRLS` role on Aiven, and that a limited `read_write` key can't delete a locked version.
bobby closed this issue 2026-11-27 15:40:36 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Reference: bobby/hapi#70