How to Test a Restore Before Disaster Strikes

How to Test a Restore Before Disaster Strikes

To test a backup restore, restore to a machine that is not the live server and prove three things: the data is complete, the service starts from it, and the result matches what you expect. Do this on a schedule, not once, because a backup you have never restored is a hypothesis rather than a safeguard. This article is about the mechanics of that rehearsal: what to restore, how to verify it, and how often to run the drill.

Pick a target that cannot hurt production

The first rule of how to test a backup restore is that the test must not be able to touch live data. That means a separate host, a separate network, and ideally a separate set of credentials. A spare machine, a staging box, or a throwaway instance in the same provider all work. What matters is that the restore target cannot reach the production database and that production cannot reach it.

Isolate by name and by address. Give the restore host its own hostname, its own firewall rules, and its own DNS entry, or none at all. If your backup tooling authenticates with a key that has write access to production, revoke that during the test or use a read only key. The goal is that a mistake during the drill, such as restoring over the wrong path, fails loudly instead of quietly.

Size the target to the job. A restore of a database dump needs enough disk for the dump plus the expanded data, plus working space. If you have never measured that, measure it now, because running out of space halfway through is one of the most common reasons a restore "fails" when the backup was fine.

Restore the backup, not a copy of the backup

The drill has to exercise the same path a real recovery would. That means pulling from the same storage location, using the same tool, and running the same commands. Copying a file from the backup server with a manual scp and calling it a restore tests your ability to copy files, not your ability to recover.

Write the recovery procedure down as a script before you need it. A useful shape is: fetch the artifact, verify its checksum, unpack or load it, then start the service against it. Here is the skeleton, with the specifics left to you:

#!/bin/sh
set -eu
BACKUP_URL="s3://example-backups/db/latest.dump"
WORK=/srv/restore
mkdir -p "$WORK"
aws s3 cp "$BACKUP_URL" "$WORK/db.dump"
sha256sum -c "$WORK/db.dump.sha256"
pg_restore --clean --if-exists -d restoredb "$WORK/db.dump"

The checksum step is not ceremony. If the backup tool writes a sidecar checksum file, verify it. If it does not, generate one at backup time and store it alongside the artifact. A truncated upload looks like a valid file until you try to load it, and a checksum catches that in seconds rather than after a long restore.

For file level backups, the equivalent is unpacking an archive to an empty directory and diffing it against expectations. For object storage, list the keys and compare counts and total bytes against the source. Whatever the medium, the rule is the same: prove the artifact is intact before you spend time loading it.

Verify the restored data, not just the exit code

A restore command that exits zero has told you almost nothing. The database may have loaded with missing tables, the archive may have skipped files it could not read, or the application may have started against an empty schema and reported healthy. Verification is the part most people skip, and it is the part that turns a drill into evidence.

Start with structure. For a relational database, check that the expected schemas, tables, and indexes exist and that row counts are in the range you expect. A query like this gives you a quick fingerprint:

SELECT schemaname, relname, n_live_tup
FROM pg_stat_user_tables
ORDER BY n_live_tup DESC
LIMIT 20;

Compare the output against the same query on production, taken at a known point. Exact equality is not the goal, since production keeps moving, but a table that should hold millions of rows and holds zero is a red flag. Do the same for the application layer: log in with a test account, load a page that reads from the database, and check that the response is sane.

For file backups, verify a sample. Pick a handful of important paths, confirm they exist in the restored tree, and compare their checksums against the source. If you keep a manifest of files and hashes at backup time, this becomes mechanical. If you do not, start keeping one.

Finally, verify the application configuration. A restore that brings back the database but leaves the app pointed at the old host is not a recovery. Check the config file, the connection string, and any environment variables the service reads at startup. Confirm the restored service is talking to the restored data and nothing else.

Know what a good backup looks like before you restore it

Some failures are visible before you run anything. If your backup tool writes a header, inspect it. A database dump from a common tool begins with a line identifying the format and version, and a mismatch between that version and the server you are restoring into is a known source of trouble. For a custom format dump, the header looks like this:

head -c 5 db.dump
PGDMP

If the file does not start with the expected magic bytes, stop and investigate the backup job rather than the restore. The same principle applies to archives: run a listing command such as tar -tzf archive.tar.gz and confirm the output ends cleanly. A gzip stream that ends with an error is truncated, and no amount of restore effort will fix it.

Check the configuration that produces the backup, too. Retention settings are a frequent trap: a policy that keeps seven daily copies and no weekly or monthly copy means a problem that goes unnoticed for a fortnight leaves you with nothing older than the problem. Read the schedule, the retention rule, and the destination, and confirm they match what you believe. This is the cheapest possible test, and it catches a surprising number of real incidents.

How often to rehearse, and what to record

Rehearse on a cadence tied to change, not to the calendar alone. Restore after any change to the backup tooling, the schema, the storage destination, or the application's startup process. Beyond that, a regular drill at a frequency you will actually sustain is worth more than an ambitious schedule you skip. Many teams settle on a monthly restore of the most critical dataset and a quarterly full rehearsal of everything, including the application and its config.

Record the result each time. Note the date, what was restored, how long it took, what failed, and what you changed as a result. The timing matters because it tells you whether your recovery objective is realistic; a restore that takes hours is fine if you planned for hours and a problem if you assumed minutes. Keep the record somewhere the on call engineer can find it, not in someone's head.

Treat every failure in the drill as a win. A missing table, a bad checksum, an expired credential, a config pointing at the old host: each one is a problem you found on your own terms. Fix it, then run the drill again to prove the fix.

What to do next

Pick your single most important dataset and schedule a restore into an isolated host this week, using the same script and the same tool a real recovery would use. Verify the checksum, check the row counts, start the application against it, and write down what broke. Then put the drill on a repeating schedule and keep the written procedure next to the backups, so the next person who needs it does not have to invent it under pressure.

Related articles

Subscribe to our newsletter

Get the latest hosting tips, performance insights, and industry news.