Goal
"We have backups" means nothing until a restore worked. Run a small database with live writes, take backups the way production would, then destroy the database and restore it while the clock runs. You measure the real RPO (how much data you lost) and RTO (how long you were down), compare them with the targets, and write the drill report.
Before you start
- Docker works. Write the targets down before the drill: RPO 15 minutes, RTO 30 minutes.
- Start the database and a writer that inserts one row every second (this is your "business"):
docker run -d --name pg -e POSTGRES_PASSWORD=lab -v pgdata:/var/lib/postgresql/data postgres:16 sleep 5; docker exec pg psql -U postgres -c "create table orders(id serial primary key, at timestamptz default now());" (while true; do docker exec pg psql -qU postgres -c "insert into orders default values;" >/dev/null 2>&1; sleep 1; done) &
Tasks
Tick a task when it is done. Only your browser remembers it.
- Scope: write in 3 lines what you test (one database), what "restored" means (the app can read and write, the newest row is known) and who decides the all-clear.
- Take a logical backup with
pg_dump -Fcinto a folder outside the container, with the date in the name, and record its checksum. - Let the writer run for 2 more minutes (these rows will be lost — that is your RPO).
- Disaster: stop the writer, remove the container and the volume. Start the stopwatch (T+0).
- Restore: new container, new volume,
pg_restore, check the row count and the newest timestamp. Restart the writer. Stop the stopwatch at the first successful write. - Calculate the real RPO (newest row before the disaster minus newest restored row) and the real RTO (T+0 to the first write). Did you meet the targets?
- Write the drill report: timeline, numbers, what went wrong, three actions (for example: backups every 5 minutes, WAL archiving for point-in-time restore, a scripted restore).
Check your work
ls -l ~/drill-backups/
sha256sum -c ~/drill-backups/*.sha256
docker exec pg psql -U postgres -tc "select count(*), max(at) from orders;"
cat ~/drill-backups/REPORT.md- The checksum check prints
OK. - After the restore the table has rows, and new rows arrive again.
- The report has T+0, the restore end, the measured RPO and RTO, and whether each target was met.
Hints
Show the hints
docker exec pg pg_dump -U postgres -Fc postgres > file.dumpwrites the dump on the host.- Note the newest row just before the disaster:
select max(at) from orders;. docker exec -i pg pg_restore -U postgres -d postgres --clean --if-exists < file.dump.- A logical dump only gives you the moment of the dump. Point-in-time recovery needs a base backup plus archived WAL (
pg_basebackup,archive_command, or tools like pgBackRest / WAL-G). date +%sat T+0 and at the end gives the RTO in seconds.
Solution
Show the solution
- Backup with checksum.
- Wait 2 minutes, then note the last row and cause the disaster.
- Restore.
docker run -d --name pg -e POSTGRES_PASSWORD=lab -v pgdata:/var/lib/postgresql/data postgres:16 sleep 5; docker exec -i pg pg_restore -U postgres -d postgres --clean --if-exists < $F docker exec pg psql -U postgres -tc "select count(*), max(at) from orders;" docker exec pg psql -qU postgres -c "insert into orders default values;" && T1=$(date +%s) echo "RTO: $((T1 - T0)) s" RTO: 41 s - RPO =
max(at)before the disaster minusmax(at)after the restore, here about 2 minutes (the rows written after the dump). The RTO of under a minute is far below the target of 30 minutes, but only because you knew every command; a real team also needs time to detect, decide and communicate. - The report.~/drill-backups/REPORT.md
# Restore drill 2026-11-14 — orders database Targets: RPO 15 min, RTO 30 min. Result: RPO 2 min (met), RTO 41 s (met, technical part only). Timeline: 10:02 dump taken · 10:04 disaster (T+0) · 10:04:41 first write after restore. Went wrong: restore steps were typed by hand; no alert would have told us the DB was gone. Actions: 1) dumps every 5 min + WAL archiving (owner: ops, by 30 Nov) 2) script the restore and run this drill every quarter 3) alert on "no new orders for 2 min"
My notes
No notes yet.