Backup Strategy & Restore Drills
Nobody needs backups. Everybody needs restores. A backup strategy is the set of answers to "what can we get back, how old will it be, how long will it take, and have we actually tried?" This lesson turns those questions into numbers, a retention policy you can compute, and a restore drill you can script.
Two numbers first: RPO and RTO
| Term | Question | Driven by |
|---|---|---|
| RPO (recovery point objective) | how much data may we lose? "at most 1 hour of orders" | how often you back up (or replicate) |
| RTO (recovery time objective) | how long may the restore take? "back online within 4 hours" | backup size, restore speed, automation, practice |
A nightly backup means an RPO of up to 24 hours. If the business says one hour, you need hourly snapshots, continuous database log archiving (PostgreSQL WAL archiving, MySQL binlogs) or replication. Replication alone is not a backup: a DROP TABLE replicates in milliseconds.
3-2-1 (and the modern additions)
- 3 copies of the data (the original plus two backups),
- on 2 different kinds of storage (the server's disk and an object store, say),
- 1 of them off-site (another region, another provider).
Modern versions add 1 copy offline or immutable (object lock / WORM storage, or credentials the server doesn't have, so ransomware on the server can't delete the backups) and 0 errors in the last restore test. On a cloud provider, "off-site" also means "outside the account": a compromised or deleted account takes its in-account snapshots with it.
Retention: grandfather-father-son
Keeping every daily backup forever is expensive; keeping only a week is dangerous (corruption often goes unnoticed for longer). A common policy keeps the last 7 dailies, the last 4 weeklies (Sundays) and the last 12 monthlies (the 1st). Tools like restic (forget --keep-daily 7 --keep-weekly 4 --keep-monthly 12) and Borg (prune) implement the same idea (they keep the newest backup of each day, week and month rather than a fixed weekday, but the shape is the same); here is the simple Sunday/first-of-month version as code, run for a server that has taken one backup per day since January:
from datetime import date, timedelta
def keep(backups, daily=7, weekly=4, monthly=12):
kept = {}
for d in sorted(backups, reverse=True)[:daily]:
kept.setdefault(d, []).append("daily")
sundays = [d for d in sorted(backups, reverse=True) if d.weekday() == 6]
for d in sundays[:weekly]:
kept.setdefault(d, []).append("weekly")
firsts = [d for d in sorted(backups, reverse=True) if d.day == 1]
for d in firsts[:monthly]:
kept.setdefault(d, []).append("monthly")
return kept
backups = [date(2026, 1, 1) + timedelta(days=i) for i in range(120)] # Jan 1 .. Apr 30
kept = keep(backups)
for d in sorted(kept, reverse=True):
print(d.isoformat(), d.strftime("%a"), "+".join(kept[d]))
print(f"{len(backups)} backups taken, {len(kept)} kept")2026-04-30 Thu daily
2026-04-29 Wed daily
2026-04-28 Tue daily
2026-04-27 Mon daily
2026-04-26 Sun daily+weekly
2026-04-25 Sat daily
2026-04-24 Fri daily
2026-04-19 Sun weekly
2026-04-12 Sun weekly
2026-04-05 Sun weekly
2026-04-01 Wed monthly
2026-03-01 Sun monthly
2026-02-01 Sun monthly
2026-01-01 Thu monthly
120 backups taken, 14 kept
Fourteen backups cover four months with daily precision for the last week. Note that the policy is computed from the backup dates, not "now", so a backup job that silently stopped two weeks ago doesn't make the pruning delete the only recent copies; restic and Borg behave the same way.
A restore drill you can run
The only proof that a backup works is a restore, compared against the original. A minimal drill: back up with a manifest of checksums, restore into a scratch directory, verify every file, and compare the trees:
mkdir -p srv/app/config srv/app/uploads
echo "db_host=10.0.0.30" > srv/app/config/app.ini
for i in 1 2 3; do head -c 2000 /dev/zero | tr '\0' "$i" > srv/app/uploads/img$i.bin; done
# --- backup: archive + checksum manifest, both stored together
(cd srv && find app -type f -print0 | sort -z | xargs -0 sha256sum) > MANIFEST.sha256
tar -C srv -czf backup-2026-01-15.tar.gz app
sha256sum backup-2026-01-15.tar.gz > backup-2026-01-15.tar.gz.sha256
# --- later: a restore drill into an empty scratch directory
sha256sum -c backup-2026-01-15.tar.gz.sha256
mkdir restore && tar -C restore -xzf backup-2026-01-15.tar.gz
(cd restore && sha256sum -c --quiet ../MANIFEST.sha256) && echo "all $(wc -l < MANIFEST.sha256) files verified"
diff -r srv/app restore/app && echo "trees identical"
# --- what a failed drill looks like: a corrupted archive
printf 'X' | dd of=backup-2026-01-15.tar.gz bs=1 seek=200 conv=notrunc status=none
sha256sum -c backup-2026-01-15.tar.gz.sha256backup-2026-01-15.tar.gz: OK
all 4 files verified
trees identical
backup-2026-01-15.tar.gz: FAILED
sha256sum: WARNING: 1 computed checksum did NOT match
The archive checksum catches storage corruption before you even unpack; the manifest catches files that are missing or changed inside it. In a real drill you also:
- restore onto another machine (the original may be gone in a real disaster),
- start the application on the restored data and run a smoke test (a database backup is only good if the database starts and a known query returns the known answer),
- time it and compare with the RTO,
- write down what was missing (credentials, a config file that lived only on the old server, DNS changes) and fix the runbook.
Schedule drills (quarterly is common) and automate the boring part: a timer that restores last night's backup into a scratch VM or container and runs the checks turns "we have backups" into a monitored fact.
What to back up
| Back up | Usually not |
|---|---|
| application data, database dumps or snapshots, uploads | the OS and packages (rebuild them from an image or Ansible) |
/etc (or better, the configuration management repo that generates it) |
caches, /tmp, build artifacts that CI can recreate |
| TLS private keys and secrets, encrypted | container images (they are in a registry; back up the registry if it's yours) |
| the backup tool's own keys and the restore runbook, stored elsewhere | logs, unless a retention rule says so |
The last row on the left is the one that bites: an encrypted backup whose key lived only on the server you lost is no backup.
Test yourself
The business can accept losing at most 15 minutes of orders. Which objective is that?
- RTO
- RPO
- SLA
- MTTR
Why is database replication not a backup?
- Replicas are slow
- Mistakes such as a DROP TABLE or corruption replicate to the replica immediately
- Replicas can't be read
- It costs more
What is the only reliable proof that backups work?
- The backup job exits with 0
- A regular restore test that verifies the data and starts the application
- Large backup files
- Using 3-2-1