Topic 080 / Core
Backup and restore: point-in-time recovery, restore testing
Chapter 5.6 · Operational Storage and the Data Lifecycle
What and why
A backup that is never restored is a hope, not a guarantee. Backup and restore combines periodic full/incremental backups with continuous log archiving so data can be recovered not just to the last backup, but to any point in time before a failure — and restore testing proves that recovery actually works. Builds on: → 68 (write-ahead logging and durability).
Diagram
full backup (day 0) ──WAL archived continuously──► … ──failure (14:32)
▲
restore target: 14:31:59
(restore full backup, then replay archived WAL up to the target time)
How it works
- Take periodic full backups, plus continuous incremental backups or continuous write-ahead log archiving between them.
- Point-in-time recovery (PITR): restore the last full backup, then replay archived WAL up to any chosen moment before the failure — not only "the last backup."
- Restore testing: periodically restore a backup into a separate environment and verify the data is complete and usable — this is what makes a backup real.
- Set retention long enough to meet the required recovery point, and expire the rest.
Practical example
(illustrative). A bad DELETE with no WHERE clause runs at
14:32. PITR restores to 14:31:59 — one second before the mistake — instead of losing
everything back to the last nightly full backup at, say, 02:00.
When to use it
- Use when: losing more than a few minutes of data is unacceptable.
- Avoid when: the business explicitly accepts losing up to a day's data — then full-backup-only recovery is a reasonable, named trade-off, not an oversight.
- Failure scenarios: a backup that was never restored and turns out to be corrupted or incomplete only when it's actually needed; WAL archives rotated or deleted before being copied off the primary, breaking the replay chain.
- Simpler alternative: a daily full backup with no PITR, for genuinely low-stakes data — as long as it's a decision, not an accident.
Practice
(20–30 min, lab Postgres). Take a base backup of the lab database, make a few changes, then simulate a mistake (delete some rows). Restore to a point in time just before the mistake, using the archived WAL. Done when the restored data is correct up to, but not including, the mistake — confirmed by actually restoring, not by assuming the backup is good.
Shared lab setupKey takeaway
PITR recovers to any moment before a failure, not just the last backup — and an untested backup is not a backup. Done when you can: perform a restore to a specific point in time and verify it. Used next in → 195 (disaster recovery, RTO and RPO).
References
None — this topic makes no external claims.
Source directory