# PostgreSQL Backup Plan — Hetzner Storage Box Goal: automated backups of the `postgres-hetzner` database (namespace `database`) to an off-cluster Hetzner Storage Box, using the plain-manifest style of this repo. ## Current state - Postgres: single-replica Deployment `postgres-hetzner`, ns `database`, data on `hcloud-volumes` PVC (`postgres-hetzner-pvc`). - Image: `rg.mariushome.lt/custom-postgres` (postgres 18.4 + pgvector, **already contains rclone** — can talk SFTP directly, no new image build needed). - Credentials live in existing `postgres-secret` (POSTGRES_USER / POSTGRES_PASSWORD). - No backup automation exists today. ## Proposed approach CronJob + `pg_dump` + `rclone` over SFTP (logical backups, no sidecar, no new Docker image, no extra PVC — stream dump into `rclone rcat`). ### 1. Storage Box (one-time, manual) - Create sub-account/directory, e.g. `postgres-backups/`. - SFTP endpoint: `uXXXXX@uXXXXX.your-storagebox.de:23`. ### 2. Secrets (gitignored — never committed) - New Secret `postgres-backup-secret` in `database` ns: - `SFTP_HOST`, `SFTP_USER`, `SFTP_PASS` (or `SFTP_KEY`). - DB credentials reused from existing `postgres-secret`. ### 3. New manifests — `PostgreSQL/backup/` - `postgres_backup_rclone_configmap.yaml` — rclone.conf with `storagebox:` SFTP remote. - `postgres_backup_cronjob.yaml` — CronJob: - schedule: (TBD, e.g. daily `0 3 * * *`) - image `rg.mariushome.lt/custom-postgres` - command: `pg_dumpall | rclone rcat storagebox:postgres-backups/dump-$(date).pgdump` - retention: `rclone delete --min-age Nd` (TBD) before/after upload - `concurrencyPolicy: Forbid`, history limits 1/1 - `backoffLimit: 2` ### 4. Verification - Test run: `kubectl create job --from=cronjob/postgres-backup backup-test -n database` - Check logs; verify file on Storage Box via `rclone lsd` from a debug pod. - Document restore procedure (`pg_restore` / `psql`) in this file after first successful backup. ### 5. Later (optional) - PrometheusRule alert on failed/timed-out CronJob (kube-prometheus-stack already selects all). - Restore drill runbook. ## Open questions (fill in before implementation) 1. **Backup scope**: `pg_dumpall` (all DBs + roles/globals) vs. per-database `pg_dump` loop? → 2. **Physical vs. logical**: logical `pg_dumpall` assumed OK (small homelab DB, simple restore). PITR/WAL archiving is out of scope — confirm? → 3. **Schedule**: e.g. daily at 03:00 UTC? → 4. **Retention**: keep N days? also keep weeklies/monthlies? → 5. **Storage Box auth**: SSH key or password? → 6. **Storage Box host/account**: hostname + username once the sub-account exists? → 7. **Backup filename scheme**: OK with `postgres-backup-YYYYMMDD-HHMM.pgdump`? → 8. **Alerting**: add PrometheusRule for failed CronJob now, or later? → ## Notes / constraints - Dump size must fit in pod ephemeral storage if not streaming; streaming via `rclone rcat` avoids any local disk requirement. - Storage Box SFTP uses port 23 (Hetzner default). - Downtime is NOT required — `pg_dumpall` is online and consistent per DB.