Validating Backups
For a year Pedal's backup job reported "success" every night. When the team finally needed a restore, the archive held nothing after March: a full disk had made archive_command fail, and nobody was watching. A backup that has never been restored is a hope, not a backup.
The rule
A backup exists only when you have restored it, checked it and timed it.
Validation has layers, from cheap to conclusive:
- Watch the job itself. Alert when a backup job fails or is missing. For WAL archiving,
pg_stat_archivershowsfailed_countandlast_failed_time.
SELECT archived_count, last_archived_time, failed_count, last_failed_time
FROM pg_stat_archiver;Check the file. For a base backup,
pg_verifybackupcompares every file against thebackup_manifestchecksums and checks the WAL needed for consistency (plain-format backups; tar format is supported from version 18). For a dump,pg_restore -l pedal.dumpproves the archive is readable and lists what is inside. Neither proves the data restores.Restore it. On a separate server, regularly — for example weekly, automated — restore the latest backup, and for physical backups recover to a recent point in time.
Check the contents. Run sanity queries: row counts of key tables, the newest
started_atinrentals, a known member's record. Compare with the numbers recorded when the backup was taken.Time it. Measure how long the restore took. Two targets make the numbers meaningful:
- RPO (recovery point objective): how much recent data you can afford to lose. Nightly dumps alone mean up to a day; WAL archiving shrinks it to minutes.
- RTO (recovery time objective): how long you can afford to be down. If the test restore takes six hours and the RTO is one hour, the backup design fails the test even though the data is fine.
Also keep at least one copy away from the server and its account, so one mistake or one attacker cannot delete both the database and its backups.
The shortcut
Every backup plan must answer three questions with evidence, not belief: "When did we last restore it? Was the data right? How long did it take?" If any answer is "we have not tried", that is the next task.
Restore
A script restores Sunday's base backup to a spare server and recovers to Monday 09:00 using the WAL archive.
The trap is treating a green "backup succeeded" message as proof. It only says a command exited cleanly, not that the result can rebuild your data.
Drills
Answer fast — trust the rule.
Which view shows whether WAL archiving has been failing?
What does pg_verifybackup check?
The business can lose at most 10 minutes of data. Which figure is that?
The restore test succeeds with correct data but takes five hours, and the RTO is two hours. What is the verdict?
Remember
- A backup exists only when you have restored it, checked it and timed it.
- Watch the job, verify the file, restore, check contents, time it against RPO and RTO.
- Keep a copy away from the server and its account.
