Database Backups and Restore
Restorable copies and a tested restore path
Database backups combine automated snapshots, transaction-log PITR and physical/logical exports. Knowing exactly what to restore — a table, a database, a point-in-time — determines your RPO and recovery speed.
What you will learn
- Compose snapshot + transaction-log backups for PITR
- Choose logical (dump) vs physical (file) backups
- Plan and validate restores against RPO/RTO
A snapshot is crash-consistent point-in-time; transaction logs fill the gap granularly. Managed databases automate both into PITR (restore to any second). Dumps (pg_dump/mysqldump) back up logical data but restore slowly.
What is this?
Physical: volume/instance snapshots + managed automated backups (AWS Backup/RDS, Azure restore points, Cloud SQL backups) with PITR via binary logs. Logical: pg_dump, mysqldump, SQL BACPAC, gcloud exports — portable, engine-aware, but slower and less granular. Restore targets: same instance (in-place), new instance (cautious), point-in-time (undo a bad migration/deletion). RPO/RTO decision point: dump daily vs snapshot hourly vs log-applied PITR.
Why do you need it?
- 'Oops, I dropped a table' is the #1 restore trigger — PITR saves the day.
- Snapshot restores are minutes; a 5-day-old full dump 'restore' can be hours.
- Logical dumps are needed for engine upgrades and cross-engine migration.
- A tested restore = a real RPO/RTO number, not a promise.
Mental model
A daily photograph of your desk plus a per-minute list of what changed
Snapshot + transaction logs
The photo (snapshot) captures the state each morning; notes of every paper moved (transaction log) reconstruct how it looked at 3:07pm — that's point-in-time recovery.
How it works
- Automated snapshots run on a schedule; each captures the whole store consistently.
- Binary/transaction logs record every committed change; PITR replays them to an exact timestamp.
- Restores: choose a snapshot → restore → optionally apply logs up to the target time.
- Logical dumps (pg_dump) produce portable SQL/text; import as a fresh DB (slower, coherent).
- Cross-region: copy backups/vaults for region-loss recovery.
PITR timeline.
Examples
Point-in-time restore
# RDS: create new DB restored to a specific timeaws rds restore-db-instance-to-point-in-time \ --source-db-instance app-db \ --target-db-instance app-db-pitr \ --restore-time 2026-09-22T11:59:00Z \ --use-latest-restorable-time# Postgres logical dumppg_dump -h <endpoint> -U app dbname > full.sqlpsql -h restored -U app dbname < full.sqlPITR for incidents, dumps for portability or engine/OS moves.
In production
- A fintech runs Aurora PITR with 35-day retention: restoring a bad release is a 10-minute op.
- Azure SQL keeps 7-day PITR plus long-term backups vaulted for annual audits.
- Cloud SQL nightly export to GCS parquet feeds the warehouse without touching prod.
Best practices
- Set retention from RPO/legal demands, and test a restore on the consumer side.
- Prefer instant-snapshot restores for speed; dump for portability.
- Rehearse 'drop the table' PITR in staging quarterly.
- Keep backup/restore credentials scoped and audit restore provenance.
Common mistakes
- Restoring to the same instance in place instead of a new instance for a change.
- Dumps with no binlog coverage → gaps beyond last full backup.
- Backing up the DB but not the app config/migrations it needs to run.
- Assuming 'restore point' and 'PITR' are the same granularity (they differ!).
Common issues
PITR returns 'no restorable time' near crashLog retention shorter than the RPO needed
Lengthen binlog/backup retention to cover the longest plausible recovery window.
Logical restore fails on foreign keysIndependent-table import order
Use --data-only with constraints disabled, or the managed import/export path.
Debugging tips
- Restore fails fast? Usually grants on the target instance — check DB user perms.
- PITR low on time-range: verify transaction log retention equals retention.
- Restore slow: choose file-by-file or parallel import for big dumps.
- After PITR, quarantine the window: restore to a *new* instance and inspect before flipping.
Interview checkpoint
Hands-on lab
- Enable automated backups + PITR on a database
- Delete a table and restore to a point in time
- Verify rows match the restore manifest
Automate Backup and Practice a PITR Restore
30 min · intermediate
Quick quiz
What makes point-in-time recovery possible beyond the last snapshot?