Skip to content

Lesson 12 of 13 · 18m

The Restore Runbook

Dependencies first, PITR to the minute before the damage, a verification gate, then traffic — DNS TTL lowered long before the fire.

A restore is a dependency graph executed by a tired human under paging pressure. The runbook exists because the ordering is not obvious at 3 AM and the mistakes are expensive — restoring the app before its database, flipping DNS before verification, or the classic: restoring data back onto the compromised host the attacker is still sitting in.

The ordering constraint

Dependencies first, always. Identity and secrets before data (you need credentials, TLS keys, and repo passwords to restore anything), data before app (the app is useless and may actively corrupt state without its database), app before traffic (verify before you invite the world back).

Concretely, a Postgres-centric restore:

  1. Provision clean. If compromise is suspected: rebuild the host from a known-good image and rotate credentials first. Restoring into the blast radius just hands the data back to whoever took it. If it's hardware failure, provision normally.
  2. Restore the database. pgBackRest restore, or PITR from base backup + WAL: PostgreSQL 12+ writes a recovery.signal file and sets recovery_target_time — point it at the minute before the damage ('2026-11-16 14:31:59', not after), with recovery_target_action = promote (or pause to inspect before committing). Targets can also be a named point (pg_create_restore_point beforehand), a transaction id (recovery_target_xid), or an LSN, with recovery_target_inclusive covering the edge where the bad transaction's own commit is the boundary. recovery_target_action = pause plus pg_wal_replay_pause()/pg_wal_replay_resume() lets you inspect tables mid-replay and step toward the damage instead of guessing the exact second once.
  3. Restore the file layer. restic restore <snapshot-id> --target / --include /srv/uploads for partial work; restic mount for browse-and-grab. Single table from a custom-format dump: pg_restore -t orders -d dbname dump.pgc.
  4. Verify before traffic. Row counts against expected ranges, the app's own health checks, restic check, a human poking the critical paths. This is a gate, not a step — the runbook says what verifies it.
  5. Flip traffic. DNS is last, and TTL is the trap: lowering a 24-hour TTL during the incident does nothing for records already cached in resolvers worldwide. Lower TTLs before the disaster, as standing policy on records DR will touch. If a CDN or load balancer fronts you, the flip happens there instead — same verification-first rule. And keep the failover inside the existing hosted zone: changing DNS providers mid-incident propagates on registrar delegation TTLs measured in days, not the record TTL you lowered.

Partial restores are a skill

Most real restores are surgical: one dropped table, one nuked bucket path, yesterday's config before the bad deploy. Know the incisions per tool: pg_restore -t, --include/--exclude on restic restore, mysqldump on the restored scratch DB then export the one table, pg_basebackup+PITR to a throwaway instance for forensic row mining without touching production.

Two mechanical details worth having written down before the night you need them. recovery_target_timeline = 'latest' tells Postgres to follow the newest timeline when the archive has already branched from a previous PITR — omitting it can replay into a dead branch. And recovery.signal means "recover then serve"; standby.signal means "keep following a primary" — write the wrong one and your restore comes up as a replica chasing a dead master.

The wrong model

"Restore = untar everything and see." The untar version has no ordering, no verification gate, no damage-point logic — and replays the corruption you were trying to escape. PITR to after the DROP TABLE faithfully replays the DROP TABLE.

The practice

One page: the ordered steps, the literal commands, the verification gate's contents, the comms step (status page, who posts it — and the status page lives outside the failure domain, on a hosted service or second provider, not on the infrastructure currently on fire), and the decision points (restore point selection, restore-vs-rebuild). Literal commands means copy-pasteable — restic -r s3:s3.amazonaws.com/bucket/repo snapshots, the actual repo URL, the actual target paths — because at 3 AM nobody should be reconstructing flags from memory. Rehearsed quarterly — the drill is where you learn that step 2 needs the repo password that lives in a password manager whose master key is on the dead laptop. Write the page, time the steps, fix what the drill breaks.

Was this lesson helpful?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.