Skip to content

Production PostgreSQL backups

Production deployments install two systemd timers:

  • awesome-postgres-backup.timer creates a daily encrypted SQL archive.
  • awesome-postgres-restore-check.timer restores the newest archive into an isolated disposable PostgreSQL container every week.

The deployment also creates a backup immediately before replacing application containers when the production PostgreSQL service is running.

Failure alerts

Both services declare OnFailure=awesome-watchdog-notify@%n.service, so a failed backup or restore check sends its result and last log lines to the owner's Telegram chat through the host watchdog. A successful restore check touches /var/backups/awesome-localstack/postgres/restore-check.ok. The watchdog also reports when the newest daily archive is older than 26 hours or that stamp is older than 8 days, which catches a timer that silently stopped running. See the lean monitoring plan.

Required vault configuration

Add a dedicated encryption passphrase to the encrypted production vault:

backup_encryption_passphrase: a-separate-random-secret-of-at-least-32-characters

Keep an offline copy of this passphrase. The encrypted backups cannot be recovered without it.

For off-host copies, configure an existing rsync destination:

backup_remote_target: [email protected]:/srv/backups/awesome-testing

The server's root account must already have SSH authentication and host-key verification configured for the destination. When the setting is empty, local encrypted backups and restore verification still run, but the setup does not protect against loss of the entire server.

Retention and locations

By default, the server keeps:

  • 7 newest daily archives under /var/backups/awesome-localstack/postgres/daily.
  • 4 newest Sunday archives under /var/backups/awesome-localstack/postgres/weekly.

Every encrypted archive has a SHA-256 checksum sidecar. No plaintext dump is written to disk.

Manual operations

Create a backup:

sudo systemctl start awesome-postgres-backup.service
sudo journalctl -u awesome-postgres-backup.service

Verify the newest backup by performing an isolated restore:

sudo systemctl start awesome-postgres-restore-check.service
sudo journalctl -u awesome-postgres-restore-check.service

Archives are taken with --no-owner, so restored warehouse, payment and notification schemas belong to the superuser at first. Recreate warehouse-service, payment-service and notification-service after a restore (docker compose -f docker-compose.server.yml up -d warehouse-service payment-service notification-service): their one-shot postgres-roles dependency hands each schema and its tables back to the warehouse, payment and notification roles before the services start.

Inspect timer state:

systemctl list-timers 'awesome-postgres-*'

Recovery

Copy an encrypted archive and its .sha256 sidecar to a trusted machine with Docker, GNU gzip, and OpenSSL. Verify the checksum, decrypt it, and pipe the SQL into a clean PostgreSQL 19 database (the pinned postgres_restore_image; dumps taken from PostgreSQL 16 restore there too). Use the same OpenSSL parameters as the automation: AES-256-CBC, PBKDF2, and 200,000 iterations.