A backup you have never restored is not a backup, it's hope. Restore must be tested as regularly as the copies are taken: otherwise one day you'll discover you've been collecting broken dumps for six months — at the exact moment they're needed desperately.
The minimal working pipeline
#!/usr/bin/env bash
set -euo pipefail
STAMP=$(date +%Y%m%d-%H%M)
export PGPASSWORD="$DB_PASS" # from a secret manager, not the repo
# dump + encryption + shipping
pg_dump --format=custom "$DB_NAME" \
| gpg --encrypt --recipient ops@example.com \
> "dump-$STAMP.gpg"
aws s3 cp "dump-$STAMP.gpg" "s3://backups/pg/$HOST/$STAMP/dump.gpg"
# local rotation - keep nothing next to production
find /var/backups/pg -name 'dump-*.gpg' -mtime +3 -delete
Three properties without which this is not a pipeline: encryption before shipping, an off-host copy (S3/bucket), rotation both locally and remotely.
What must be verified
- Restoring onto another host. "It works on this server" doesn't count: the target host in a disaster has its own tool versions and its own free disk. A restore drill runs on a separate VM, on a schedule.
- Rotation. Retention is written into the bucket policy (lifecycle rules), not kept in someone's head — and not "we'll delete when space runs out".
- Encryption with a key that lives off the server. A dump without GPG next to production is just a copy of the data for whoever finds it. The encryption key lives with the recipient, not on the DB server.
The drill: what a restore check looks like
# 1. the fresh dump decrypts and restores
gpg --decrypt dump-20261113-0300.gpg > dump.custom
pg_restore -h restore-test.internal -d restore_test --clean --if-exists dump.custom
# 2. schema migrations are applied (if the dump predates the current one)
psql -h restore-test.internal restore_test < migrations/2026_11_03.sql
# 3. the application connects and responds
curl -fsS "http://restore-test.internal/api/health" | grep -q ok
# 4. record the actual elapsed time: this is your real RTO
Item four is the most important: the time the drill showed is your honest RTO to quote to applications and customers. Usually it's 2–3 times worse than "gut feeling", and that's fine — as long as it's known.
Pipeline metrics I watch in monitoring
| Metric | Alert |
|---|---|
| Time since the last successful backup | > 26 hours — the pipeline has stopped |
| Dump size | deviation from the mean > 30% — an "empty" dump or a data explosion |
| Last drill result | not run in > 30 days — hope instead of a backup |
Useful additions
- pg_dump vs continuous base backup. A logical dump is for long retention and migrations; a WAL archive (pgBackRest / barman) is for the PITR point "five minutes before the crash". Serious setups run both: dump weekly, WAL continuously.
pg_dump --jobsparallelizes dumps of large databases;--format=customlets you restore selected tables (-t) instead of the whole dump.- A "how to restore in N minutes" document: commands, order, key storage locations, contacts. An incident is not the time to recall
pg_restoreoptions.
The maturity of a backup pipeline is measured not by storage size but by the answer to: "how many minutes after losing the database is it restored and the application running?" If the answer has been tested — you have a backup. If not — hope.
pg_dump: the options that matter
| Option | Why | Default |
|---|---|---|
--format=custom (-Fc) | built-in compression, selective table restore, parallel restore | plain SQL (without any of that) |
--jobs=N | parallel dump of large tables | 1 (sequential) |
--exclude-table=... | don't haul junk tables (audit journals, staging imports) | everything |
--no-owner --no-privileges | restore under a different role (for the restore test) | include ACL |
--schema=... | a targeted backup of one schema | all |
The pipeline as a whole: the dump runs as a user with pg_read_all_data — and strictly without write privileges, so a compromised backup host can only read the data, never modify it.
PITR: the "five minutes before the crash" point
A logical dump is "yesterday's snapshot". An honest RPO requires WAL archives (pgBackRest, wal-g or the built-in archive_command):
# postgresql.conf
archive_mode = on
archive_command = 'wal-g wal-push %p' # or pgbackrest archive-push
# point-in-time restore
pgbackrest --stanza=main --set=20261113-030000F \
--type=time "--target=2026-11-13 04:57:30" restore
That's how the PITR scenario works: "we crashed at 05:03, the cause is a dropped table at 04:57 — we restore to 04:57". A logical dump can't do this: it only offers "start of the day".
RTO/RPO: how to count them honestly
| Mechanism | RPO | RTO | Keep |
|---|---|---|---|
| pg_dump nightly | up to 24 hours | time to restore the whole dump (30 min — hours) | 30–90 days |
| Continuous WAL archive | minutes | restore of the latest base backup + WAL replay (10–30 min) | 7–14 days |
| Both together (the norm) | minutes | minutes | per the policy of each |
The numbers in the columns are not dogma: your RTO is measured by a drill, not by a table. But the table honestly shows: a dump alone covers the "yesterday's snapshot" scenario, WAL — the "five minutes before the crash" one; together they cover both.