The dirty secret of most backup programs is that nobody finds out the backups are broken until the day they need them. The pipeline writes a file, the cron job reports success, the dashboard turns green, and the operator goes home. Six months later a junior engineer drops the wrong table, the recovery procedure begins, and an hour into the restore someone discovers the dump is truncated, or the encryption key was rotated, or the target MySQL version cannot replay binlogs from the source. The backup was always a file on a disk somewhere. It was never a restore.
This article is the playbook we run on managed environments to change that. It defines four levels of backup verification, each catching a different class of failure, and shows how to automate them for MySQL, PostgreSQL, and MongoDB. By the end you will be able to answer the only question an auditor or a frightened CTO actually cares about: “show me proof that the backup from last Tuesday can be restored to a running application, today.”
The four levels of backup verification
Backup verification is not a single check; it is a ladder, and each rung catches failures the rung below cannot see. A passing Level 1 says nothing about whether Level 4 will pass. Every level should run on its own schedule, with its own alert, against its own scratch infrastructure.
- Level 1 — Storage integrity. Does the file exist where the manifest says it does? Does it match the checksum recorded at backup time? Is the size within the expected band for this workload? This catches truncated uploads, silent corruption in object storage, missing files when the cron job ran on the wrong host. It does not catch a backup that is intact but logically broken.
- Level 2 — Schema restore. Can the dump be parsed and the schema recreated?
pg_restore --schema-only,mysql < schema.sql,mongorestore --dryRun. This catches dumps with a missing trailing block, unsupportedDEFINERclauses, character set mismatches, and tools-version drift between source and restore host. - Level 3 — Data restore. Does the full data load complete? Do row counts match the source within tolerance? Do indexes rebuild? Do constraints hold? Do simple read queries return sensible answers and complete in reasonable time? This catches encrypted backups that decrypt but contain corrupted pages, large tables that fail to load on a smaller target instance, indexes that OOM during rebuild.
- Level 4 — Application-level restore. Bring up an application stack pointed at the restored data. Run auth, the primary read flow, the primary write flow, and the scheduled jobs. Validate business invariants. This is the only level that confirms the backup is actually useful — that someone could log in, place an order, and trust the totals.
A program that runs Levels 1 through 4 weekly has near-certain restorability. A program that runs Level 1 only has hope.
Why teams stop at Level 1 — and why Level 1 alone is dangerous
Level 1 is cheap. The backup tool writes the manifest and the checksum, a cron compares them an hour later, and the dashboard shows a 100% pass rate. Levels 2 through 4 are expensive: they require a scratch database server, scratch storage, an automation harness, time for the restore to complete, and someone to investigate the failures that surface. Most teams quietly defer them.
The trouble is that Level 1 catches one failure mode — a missing or corrupted file — and the failure modes that actually destroy production restores are all higher up the ladder. The encryption key rotated between backup and restore. The source database had silent on-disk corruption that the physical backup faithfully captured. The dump was taken against a version of MySQL the recovery host cannot replay. The application schema migrated forward three steps and the restored database needs migrations replayed before the app will boot. None of these show up in a checksum match.
A common variant of this trap is the “monthly drill” — a manual end-to-end restore done once a month by an engineer who knows what to do. It works fine for years, then the engineer leaves, then on month thirteen the runbook is followed verbatim by someone unfamiliar with it and an undocumented step is missed. Verification belongs in automation, not in human ritual.
Implementation — Level 2 (schema restore) automation
The Level 2 job runs nightly. It pulls the most recent backup, restores the schema only into a throwaway database, asserts that the expected set of tables is present, and tears the scratch DB down. Total runtime is two to ten minutes; the alert fires when this job fails, not when it skips.
PostgreSQL with pgBackRest
#!/usr/bin/env bash
set -euo pipefail
SCRATCH=/tmp/pg-verify-$$
PGDATA="$SCRATCH/data"
mkdir -p "$PGDATA"
pgbackrest --stanza=main --type=full --pg1-path="$PGDATA" \
--recovery-option=recovery_target=immediate restore
pg_ctl -D "$PGDATA" -o "-p 55432 -k $SCRATCH" start
trap 'pg_ctl -D "$PGDATA" -o "-p 55432 -k $SCRATCH" stop -m immediate; rm -rf "$SCRATCH"' EXIT
pg_isready -h "$SCRATCH" -p 55432
psql -h "$SCRATCH" -p 55432 -d postgres -tAc \
"SELECT count(*) FROM information_schema.tables WHERE table_schema NOT IN ('pg_catalog','information_schema');" \
| tee /var/log/backup-verify/pg-tables.count
THRESHOLD=$(cat /etc/backup-verify/pg-expected-tables)
ACTUAL=$(cat /var/log/backup-verify/pg-tables.count)
[ "$ACTUAL" -ge "$THRESHOLD" ] || { echo "FAIL: $ACTUAL tables < $THRESHOLD expected"; exit 1; }
MySQL with XtraBackup
xtrabackup --copy-back --target-dir=/backup/latest/full --datadir=/var/lib/mysql-scratch
chown -R mysql:mysql /var/lib/mysql-scratch
mysqld --datadir=/var/lib/mysql-scratch --socket=/tmp/mysql-scratch.sock \
--port=33307 --pid-file=/tmp/mysql-scratch.pid --skip-networking=0 --user=mysql &
until mysqladmin -S /tmp/mysql-scratch.sock ping >/dev/null 2>&1; do sleep 1; done
TABLES=$(mysql -S /tmp/mysql-scratch.sock -Nse \
"SELECT count(*) FROM information_schema.tables WHERE table_schema NOT IN ('mysql','sys','performance_schema','information_schema');")
mysqladmin -S /tmp/mysql-scratch.sock shutdown
rm -rf /var/lib/mysql-scratch
[ "$TABLES" -ge "$(cat /etc/backup-verify/mysql-expected-tables)" ]
MongoDB with mongorestore
mongorestore --dryRun --dir=/backup/latest/mongo --archive | tee /tmp/mongo-dryrun.log
grep -q "no indexes to restore" /tmp/mongo-dryrun.log && { echo "FAIL: no indexes recovered"; exit 1; }
mongod --port 37017 --dbpath /tmp/mongo-scratch --fork --logpath /tmp/mongo-scratch.log
mongorestore --port 37017 --nsInclude="$EXPECTED_NS" --dir=/backup/latest/mongo
COLLECTIONS=$(mongosh --port 37017 --quiet --eval "db.getSiblingDB('app').getCollectionNames().length")
mongod --port 37017 --shutdown
[ "$COLLECTIONS" -ge "$(cat /etc/backup-verify/mongo-expected-collections)" ]
The expected-table-count files are committed to infrastructure-as-code; they update only when the schema deliberately changes. A backup that loads fewer tables than expected is a Level 2 failure even if the restore “succeeded.”
Implementation — Level 3 (data restore) automation
Level 3 brings the data along with the schema. It runs weekly because it costs real time and storage; the verification cluster sits idle the rest of the week or is provisioned per-run from an autoscaling group. Three classes of assertion run here.
Row counts. Compare against the source within tolerance. A 0.1% drift on hot OLTP tables is normal between backup time and verification time; a 30% drift is a broken backup or a broken comparison.
-- Run on the restored DB
SELECT table_name, n_live_tup AS row_estimate
FROM pg_stat_user_tables
WHERE schemaname = 'public'
ORDER BY table_name;
Index and constraint integrity. Indexes that survived the backup but cannot rebuild on the restore host point to subtle on-disk corruption. PostgreSQL has pg_checksums for verifying data-page checksums on a stopped cluster; MySQL InnoDB has innodb_force_recovery levels for triage but CHECKSUM TABLE for a positive assertion; MongoDB has validate().
# PostgreSQL — stopped-cluster page checksum verification
pg_checksums --check --pgdata="$PGDATA"
# MySQL — table-level checksum
mysql -e "CHECKSUM TABLE orders, order_items, payments EXTENDED;" app
# MongoDB — collection validation
mongosh --port 37017 --quiet --eval \
"db.getSiblingDB('app').orders.validate({full: true}).valid"
Index-resident query response time. A set of small, deterministic read queries against indexed columns, with response time recorded and compared to a baseline. An index that loaded but is bloated or corrupted will pass CHECKSUM TABLE and still produce 100x slower queries on the restored DB than on production. Treat any single-query response-time regression beyond 3x as a Level 3 finding.
EXPLAIN ANALYZE SELECT id, status FROM orders WHERE customer_id = 42 ORDER BY created_at DESC LIMIT 20;
The job aggregates pass/fail and writes a row to a backup_verification_runs table — date, target, level, duration, anomaly count, pass/fail. That table is the source of the dashboard described later.
Implementation — Level 4 (application-level restore)
Level 4 is the only verification level that proves the backup is useful to a human, not just to a database engine. It runs monthly for a subset and quarterly end-to-end. The shape is identical in every workload: bring up an isolated application stack, point its database connection string at the restored cluster, and run a smoke-test suite.
The smoke-test suite is application-specific and lives in the application repo, not the infrastructure repo. Four flows belong in it.
- Authentication. A user logs in with a known seeded credential, the session token is issued, and a protected endpoint returns 200. This catches restores where the
userstable loaded but a relatedsessionsortokenstable did not, or where a global salt secret was outside the database. - Primary read. The most-trafficked GET endpoint returns within a latency bound. This catches missing read replicas, cold caches that the application cannot tolerate, and indexes that loaded but are not being used.
- Primary write. A
POSTthat touches the main transactional path completes and the resulting row is readable. This catches sequences and identity columns that drifted, foreign-key constraints that loaded out of order, and unique-index violations from stale auto-increment values. - Scheduled job. Trigger a known cron job manually; assert it completes. This catches restores that load
pg_cronschedules into the wrong database, or MySQL events that fail because theDEFINERuser does not exist on the restore host.
Beyond the four flows, the Level 4 job asserts business invariants. The exact set is workload-specific; useful examples:
- Sum of active subscription amounts equals the most recent Stripe ledger snapshot to the cent.
- Count of
pendingorders matches the queue depth in the message broker within tolerance. - The most recent invoice number is greater than the most recent invoice number in the previous month’s backup.
A business-invariant failure is the most informative result a verification program produces; it usually points at a real production bug that escaped notice because the restored copy made it visible.
The quarterly DR drill — full Level 4 against production-sized data
The weekly Level 3 job runs against last night’s backup loaded into a sized-down scratch cluster. The quarterly DR drill restores production into a production-sized cluster, runs the full Level 4 suite, holds the cluster open for a few hours so engineers can poke at it, and tears it down. Three things justify the expense.
First, behaviour at scale. An index rebuild that completes in eight minutes on a 20 GB scratch may take ninety minutes on the 2 TB production-sized target; the RTO commitment lives or dies on the production-sized number. Second, region behaviour. The drill is the only time most teams confirm that cross-region restore actually works — that the KMS key is available in the recovery region, the S3 bucket policy permits the restore role, and the network paths exist. Third, the human factor. Junior engineers participate; the runbook gets read aloud; the gaps surface in a controlled setting rather than at 03:00.
The artifact from a DR drill is dated, signed, and filed in the same evidence store as the auditor will eventually request. Date, target environment, start time, finish time, the operator, the witnesses, the anomalies, and sign-off.
What to measure
Backup verification has four numbers that matter; ignore the rest. They go on the dashboard, they go in the quarterly business review, they go on the incident retrospective.
- RTO actual. Wall-clock time from “begin restore” to “Level 4 smoke tests passed.” Compare to the RTO target written into the SLA. The trend matters more than the absolute — a steadily creeping RTO over six months means the dataset has grown but the restore tooling has not.
- RPO actual. Data-freshness gap of the restored database — newest committed transaction in source minus newest committed transaction in restored copy. For continuous backup (WAL archiving, binlog streaming) this should be seconds; for nightly dumps it can be up to 24 hours. Compare to the RPO target.
- Drill frequency. Days since the last full Level 4 drill. A 90-day commitment must be auditable as a 90-day reality.
- Pass rate. Verification runs that passed Levels 1-4 over the last twelve months, divided by total runs. Anything below 90% is a backup pipeline that needs work, regardless of what the manifest checksums say.
When restores fail — common root causes
Verification programs surface a few recurring failure modes. The ones we see most often, in rough order of frequency:
- Silent source corruption captured by the backup. The on-disk pages were corrupted before the backup ran; the backup faithfully copied the corruption; verification surfaces it when the indexes refuse to rebuild on restore. The fix is upstream — page-checksum verification on the live source.
- Backup truncated mid-write. Disk fills up on the backup host, the tool writes a partial file, the success exit code never triggers, but the file ends up in object storage anyway because of a flawed retry. Catch with a size sanity check at Level 1 and a tail-marker check at Level 2.
- Encryption key rotated since backup. The KMS key alias still points where it should but the underlying key version that encrypted last month’s archive has been revoked. Always verify decryption of the oldest archive in the retention window, not just the newest.
- Tools version drift. MySQL 8.0 backups cannot be replayed by MariaDB 10.6 because the InnoDB redo format changed; PostgreSQL major-version restores require pg_upgrade. The verification host must run the same major version as the source. Pin both in IaC.
- Index OOM on smaller restore instance. The verification host has half the RAM of production; a 500 GB B-tree rebuild blows past
maintenance_work_memand the restore stalls. Size the verification host realistically. - Schema migrations applied post-backup. The application code expects schema at migration N+3; the restored database is at migration N. Boot the application against the restored DB and let the migration runner replay, then re-run Level 4 smoke tests.
Reporting — the verification dashboard
The verification dashboard is one page, four columns, one row per database. The columns are L1/L2/L3/L4. Each cell shows the result of the most recent run, the timestamp, and the duration. Cells turn yellow at 7 days stale, red at 14 days. Two stripes below each row show the 90-day pass rate and the RTO trend over the same window.
The dashboard is read by the on-call engineer at the start of shift and by the account manager once a week. It is also screenshotted as the audit artifact for SOC 2 CC9.1 and ISO 27001 A.8.13 — both controls accept a dated dashboard print as evidence of testing, provided the underlying logs are retained.
When Stack Harbor runs this for you
We design and operate backup verification ladders for our managed-operations clients — Level 1 through Level 4 on automation, the quarterly drill calendar, the dashboard, the audit evidence trail. Verification is part of the standing service rather than a project — every database in scope gets a verification status, and the on-call engineer sees its colour every shift.
For multi-region commitments, the same ladder runs against the multi-region environments DR target on a quarterly cadence; a Level 4 drill in the recovery region is what actually demonstrates the multi-region claim. For clustered environments we run a per-node restore drill in addition to the cluster-wide one, since cluster-aware backup tools sometimes succeed at the cluster level while one node’s archive is silently broken.
If you operate the cluster yourself but want a second pair of eyes, we will audit your verification program against this ladder and tell you which level is the weakest rung — usually Level 3 or 4 — and how to close the gap without rebuilding the pipeline you already have.
See also
- Restore drill cadence — how often, and what the drill must prove
- Backup verification and restore drill — cPanel/JetBackup workflow
- Disaster recovery drill — the quarterly procedure
- MySQL XtraBackup — online physical backups
- Cross-region S3 backup replication strategy
- Verifying a WordPress backup is actually restorable