Sub topic 15
Practicing a full recovery
This chapter covers how to rehearse the worst day: the server is gone, and you must rebuild from the backup alone. It assumes you have a working restic or Borg repository, a retention policy, check runs, and a documented passphrase or key location from the earlier chapters. You should be comfortable restoring single paths with restic restore or borg extract.
Why a drill is separate from verification
restic check and borg check prove the repository structure is consistent. They do not prove that:
- you can reach the repository from a new machine,
- you still have the passphrase or key outside the failed server,
- the snapshot contains the paths you need,
- the restored data is usable (a database dump that loads, a config that starts a service),
- the whole procedure fits your recovery time objective (RTO).
A drill tests the people and the documentation as well as the tool. The first drill usually exposes at least one gap, which is the point.
Decide what you are testing
Run drills at two levels. The small one is cheap and can run often. The large one takes an afternoon and should happen after major changes and at least once or twice a year.
| Level | Scope | Where | What it proves |
|---|---|---|---|
| File drill | One directory restored and compared with the live copy | Scratch directory on the same server | Data is readable and decryptable, and the restore command works |
| Rebuild drill | Whole service restored on a new machine | Fresh VM or cloud instance | Credentials, documentation, ordering, and RTO are realistic |
Write down your targets before you start. For example: RTO of 4 hours and a recovery point objective (RPO) of 24 hours. During the drill, measure the actual time and the age of the newest snapshot you restored. If either exceeds the target, the drill failed, even if every file came back.
What must exist outside the server
Assume the server and its disks are lost. Everything below must be reachable from your laptop or a password manager:
- The repository location (
sftp:[email protected]:/srv/restic/myserver, or the Borgssh://URL). - The repository passphrase. For Borg in
keyfilemode, also the exported key. Forrepokeymodes, the key lives in the repository, but the passphrase is still required. - An SSH private key (or object storage credentials) that is authorized to read the repository.
- A short runbook: OS version, packages to install, order of restore steps, and where the database dump lives in the repository.
The last item is the one most often missing. The repository holds your data, but nobody remembers a decision list at 3 a.m.
The shape of a rebuild drill
Start a clock when you begin and note timestamps at each step. Those notes become your real RTO.
Running a file drill
This script restores /etc/nginx into a scratch directory, verifies the restored data against the repository, compares it with the live files, and reports the elapsed time. It reuses the repository settings from the backup script.
#!/bin/bash
set -euo pipefail
export RESTIC_REPOSITORY=sftp:[email protected]:/srv/restic/myserver
export RESTIC_PASSWORD_FILE=/etc/restic/password
scratch=$(mktemp -d /var/tmp/restore-drill.XXXXXX)
trap 'rm -rf "$scratch"' EXIT
start=$(date +%s)
restic restore latest --target "$scratch" --include /etc/nginx --verify
elapsed=$(( $(date +%s) - start ))
test -s "$scratch/etc/nginx/nginx.conf"
if diff -r /etc/nginx "$scratch/etc/nginx"; then
echo "drill OK: restored /etc/nginx in ${elapsed}s, identical to live copy"
else
echo "drill: restored data differs from live files (may be recent edits)" >&2
fi--verify makes restic read back the restored files and compare them with the repository contents. The diff against live files can differ legitimately if you edited the configuration after the last snapshot. Treat a difference as something to explain, not always as a failure.
The Borg equivalent extracts into the current directory, so change into a scratch directory first:
export BORG_REPO=ssh://[email protected]/./borg/myserver
export BORG_PASSCOMMAND='cat /etc/borg/passphrase'
scratch=$(mktemp -d /var/tmp/restore-drill.XXXXXX)
cd "$scratch"
archive=$(borg list --last 1 --format '{archive}{NL}' ::)
time borg extract "::$archive" etc/nginx
diff -r /etc/nginx "$scratch/etc/nginx"Unlike --dry-run, which only lists what would be extracted, a real extract reads and decrypts every chunk, so it proves the data is readable.
Running a rebuild drill
On a fresh machine, assume nothing is configured. A typical sequence:
- Install the tool from your distribution or the official release binary, matching the major version used for backups.
- Put the passphrase in a root-only file and, for Borg
keyfilemode, import the key withborg key import. - Set the repository environment variables and confirm access.
- Restore into a staging directory first, not straight over
/.
export RESTIC_REPOSITORY=sftp:[email protected]:/srv/restic/myserver
export RESTIC_PASSWORD_FILE=/root/restic-password
restic snapshots
time restic restore latest --target /mnt/restore --verify
ls /mnt/restore/etc /mnt/restore/home /mnt/restore/var/wwwRestoring to staging lets you copy files into place selectively, keep the new machine's own network and host key settings, and avoid overwriting files such as /etc/fstab or /etc/hostname that describe the old hardware. Review those by hand.
Then restore the database. If you stored a pg_dumpall stream as its own snapshot, find its ID with restic snapshots and load it into a freshly installed PostgreSQL of the same major version:
SNAP=replace-with-snapshot-id
restic dump "$SNAP" /pg_dumpall.sql | sudo -u postgres psql -v ON_ERROR_STOP=1 postgresFinally, start the services and test them as a user would: load the site, log in, run a query. A restored /var/www that cannot connect to its database is a failed recovery.
Common failures found in drills
| Symptom | Likely cause | Fix |
|---|---|---|
| Wrong password or key error | Passphrase stored only on the lost server, or Borg key not exported | Store passphrase and key export in a password manager and re-test |
| SSH permission denied | The repository's authorized key was the old server's key | Document how to authorize a new key on the backup host |
| Snapshot is much older than expected | Timer failed silently for weeks | Add failure alerts (previous chapter) and check snapshot age in the drill |
| Database dump fails to load | PostgreSQL major version differs, or extensions are missing | Record the version and packages in the runbook |
| Restore takes far longer than the RTO | Slow network or large dataset | Restore critical paths first, add a local copy, or revise the RTO |
| Service will not start after restore | Missing packages, changed ownership, or secrets outside the backed-up paths | Add the paths to the backup or the steps to the runbook |
Making drills routine
A drill that happens once is a project. A drill that is scheduled becomes a habit. Put the file drill in a systemd timer like the backup, weekly or monthly, and alert on failure. Put the rebuild drill in a calendar with an owner. After each rebuild drill, update the runbook while the problems are fresh, then record: date, snapshot used, elapsed time, and issues found. Over time that log shows whether recovery is getting faster and whether the RPO and RTO targets hold.
Rotate who runs the drill. If only one person can recover the server, that person is a single point of failure, and the drill will show it.
Exercise
Your nightly file drill restores /etc/nginx, passes --verify, and reports "drill OK". Name two things it still does not prove about your ability to recover the server after a total loss, and say how a rebuild drill covers each.
Show answer
It does not prove that you can recover without the original server, because the drill runs on the same machine that already has the passphrase file, SSH key, and installed tool. A rebuild drill on a fresh machine checks that credentials and documentation exist outside the server. It also does not prove the whole service works or fits the RTO: only one directory is restored, with no database, no services started, and no measurement of total time. A rebuild drill restores everything, starts the services, tests them, and records the elapsed time against the RTO.