StackPilot

How to Test That a Backup Actually Restores, Not Just Runs

By The StackPilot Team 7 min read

Some links on this page are affiliate links. If you sign up through them we may earn a commission at no extra cost to you. We only link to services we have actually used, and commission never decides what we recommend.

You already restored something and it half-worked. The dump loaded, the tarball unpacked, and then the app threw a 500 or the newest row was three days old. The problem is almost never the backup file — it is that the test measured whether the restore command exited zero, not whether you got your service back.

Quick verdict

For most people running their own VPSes, the winner is a scripted restore to a throwaway instance that ends in an application health check, run on a schedule, with the elapsed time written down. It costs you one small scratch host and an afternoon of setup, and it is the only option that tests the thing you actually care about: whether the app comes back. The tradeoff is that it fails loudly and often in the first month, usually because of credentials or config that lived outside the backup. That is the point — you want those failures on a Tuesday afternoon, not at 3am.

What you are actually choosing between

ApproachCost shape and ops burdenCeiling and lock-in
Manual drill, quarterly, by handNo new spend; high per-run effort and the first thing dropped when the week gets busyCeiling is whatever fits on your laptop; no lock-in, no automation, no history
Scripted restore to a scratch VM, scheduledOne small always-on instance plus scratch storage; heavy build once, then near zero until it breaksBounded by scratch host size; low lock-in because the script is yours
Provider-native restore test (snapshot to temp instance)Pay for the temp instance by the hour; low effortFast for volumes, blind to application state; high lock-in — the test only exists inside that provider
Backup tool's built-in verification modeOften bundled into a mid or premium tier; low effortGood at "does this image boot", weak at "is this the right data"; medium lock-in
Third-party validation servicePremium, recurring; lowest effortHigh ceiling, but you are shipping copies of your data to a third party; high lock-in

Step by step

1. Write down what "restored" means before you touch anything. One sentence, testable. "The API answers /healthz with 200 and the orders table has a row newer than 24 hours old" is a definition. "The backup restored" is not. If you cannot state this, you will spend the drill arguing with yourself about whether it passed.

2. Confirm the archive is readable before you restore it. This is the cheap check that catches truncated uploads and missing encryption keys. For a restic repo, restic check --read-data reads every pack. For borg, borg check --verify-data. For a GPG'd tarball, decrypt to /dev/null and list the contents without unpacking:

gpg --decrypt backup-2024-06-01.tar.gz.gpg | tar -tzf - > /dev/null
pg_restore -l /backups/latest.dump | head -50

If the key lives on the same host as the backup, stop and fix that first. A backup you cannot decrypt is not a backup, and this is the single most common reason a drill dies at step one.

3. Restore somewhere else, under a different name. Never in place, never over the live database, and ideally not on the same host. Different hostname, different database name, different port. Restoring in place tests your ability to destroy production, and restoring to the same hostname hides every hardcoded host reference in your config.

4. Bring the application up against it, not just the data. Point a copy of the app at the restored database or the restored volume and let it start. This is where the failures you have not thought about live: file ownership after a tar restore, SELinux contexts, a config.php that was excluded from the backup because it held secrets, a cron job that expects a directory that only exists on the old box. Fix them in the runbook, not in your head.

5. Assert on content, not on exit codes. Row counts, checksums, and the newest timestamp. The query below is the shape of the check — a floor on volume and a ceiling on staleness:

psql -h "$SCRATCH_HOST" -U restore -d restore_test -tAc \
  "select count(*) from orders" | awk '$1 < 100000 {print "too few rows"; exit 1}'

psql -h "$SCRATCH_HOST" -U restore -d restore_test -tAc \
  "select max(created_at) from orders" | \
  xargs -I{} test {} \> "$(date -d '36 hours ago' +%FT%T)"

Pick the thresholds from your own data, not from a blog post. The point is that a check with a number in it fails when it should; a check that just runs pg_restore and greps for errors does not.

6. Time the whole thing, from decision to green health check. Not from the moment you typed the restore command. The clock starts when a human decides to restore, and it includes finding the credentials, provisioning the scratch host, and DNS. That number is your real RTO, and it is usually two to four times what you assumed.

7. Turn the drill into a script and schedule it. The manual version proves it can be done; the script proves it still can be done next quarter, when you have changed three things and forgotten two. Run it weekly or monthly, keep the last N results, and alert on failure. A restore test that nobody reads the output of is a cron job, not a control.

8. Record the runbook where the on-call person will find it. Plain text in the repo next to the backup config. Include the exact commands, the credential location, the expected duration, and the three things that broke last time.

Where this falls short

A scripted restore test does not cover partial loss. It restores everything to a clean host; it does not tell you what happens when a single table is corrupted, or when you need one file from three weeks ago and the retention policy has already rotated the base of the incremental chain. Test a point-in-time restore separately, and test it against the oldest backup you are contractually keeping.

It also does not cover scale. Restoring 40GB to a scratch box tells you nothing about whether a 4TB restore finishes inside your window, because the bottleneck moves — network, disk throughput, and restore-side decompression all behave differently at size. If your data is large, you need at least one drill at production scale, and that costs real money in scratch storage.

The scratch host itself is a maintenance burden. It drifts, it gets forgotten, it ends up running something else. Budget for rebuilding it from a snapshot each run rather than patching it.

And this is the wrong approach entirely if you are on a managed platform where you do not control the restore path. There, the honest move is to read the provider's documented restore procedure, run it once manually on a throwaway project, and write down the actual elapsed time — do not build automation around an API you do not own.

One more: if your backups are not encrypted at rest and you are restoring to a shared scratch host, you have just copied production data onto a machine with weaker controls. Encrypt the scratch volume or restore to an isolated network.

FAQ

How often should I test a backup restore?

Monthly for anything you would lose sleep over, quarterly for the rest. The frequency matters less than the consistency — a drill you run every month and read the output of beats an annual exercise nobody remembers. Run one immediately after any change to the backup config, the schema, or the host layout.

Can I test a restore without a spare server?

Yes, for the narrow question of "is the archive intact". Decrypt-and-list, restic check, borg check --verify-data, and pg_restore -l all run on the machine holding the backup and cost nothing. They do not prove the application comes back, so treat them as a smoke test between real drills, not a replacement.

What is the difference between verifying a backup and testing a restore?

Verification checks that the bytes are present and readable. A restore test checks that the bytes, once reassembled, produce a working service with the right data in it. Verification is fast, cheap, and catches corruption; restore testing is slow, expensive, and catches everything else.

Why did my restore succeed but the application still fail?

Almost always because something the app needs was never in the backup: secrets, environment files, TLS certificates, file ownership, or a database user that existed on the old host. The restore did its job. The backup scope was wrong, and the fix is to widen it and re-run the drill.

Related reading: Offsite Backup Provider for a One Person SaaS: Picks, How to Back Up a Postgres Database to Object Storage

Bottom line

Test the restore by bringing the application back, on a different host, against restored data, with a check that fails on a number rather than on an error message. Everything else — the archive checks, the timing, the schedule — exists to make that one test repeatable.

Today's step: write the one-sentence definition of "restored" for your most important service, then run the decrypt-and-list check on your newest backup. If that passes, book two hours this week to do the full restore to a scratch host.