How to Test That Your SQL Server Backups Restore
Taking a backup and knowing it will restore are two different things. This guide explains what SQL Server's own verification checks, what only a real restore can show, and a simple routine for testing restores by hand.
What RESTORE VERIFYONLY checks, and what it does not
Microsoft documents RESTORE VERIFYONLY as a check that the backup set is complete and the entire backup is readable. Its checks include that all volumes are readable, some header fields of the data pages, the checksum if one is present, and that there is enough space on the destination devices.
Microsoft also says plainly that RESTORE VERIFYONLY does not attempt to verify the structure of the data contained in the backup volumes. A backup can be readable and still hold a database that is damaged inside.
- VERIFYONLY is quick and worth running, but it is not a restore
- If the backup was taken without a backup checksum, VERIFYONLY has less to verify
Use backup checksums
Microsoft describes an optional backup checksum that BACKUP can write and RESTORE can validate. When a backup is taken with WITH CHECKSUM, BACKUP also verifies page checksums as it reads the pages, and a restore can use the backup checksum to confirm the backup was not corrupted. Microsoft notes there can be a performance cost, so it suggests watching CPU use and the effect on concurrent work.
- Take backups WITH CHECKSUM where you can afford the overhead
- Restore WITH CHECKSUM so a backup without one fails loudly instead of passing unchecked
Restore it somewhere else, then run DBCC CHECKDB
The strongest test is to restore the backup to a scratch database, ideally on a different server than production, and run DBCC CHECKDB against the restored copy. CHECKDB checks the logical and physical integrity of the objects in the database, so it finds problems that a readable backup file can hide. Restoring also tells you how long recovery takes, which is the figure that matters during an outage.
- Restore with a different database name and MOVE the files so nothing overwrites production
- Run DBCC CHECKDB on the restored copy and keep the result
- Write down how long the restore took and how much space it needed
- Drop the scratch database afterwards
Why teams skip it
Restores need disk space for a full copy of the database, time on a server that is not busy, and someone to remember. For large databases the backup file is also big to copy to another machine, which is why the test is best run on a server close to where the backups are stored.
A simple routine
- Pick a schedule, for example monthly, and rotate through your databases
- Restore the latest full backup and any differential or log backups you would need
- Run DBCC CHECKDB on the result and keep the output
- Record the restore time and compare it with the recovery time your business expects
- Investigate any failure at once; the next backup may have the same problem
Sources
- RESTORE Statements - VERIFYONLY (Transact-SQL), Microsoft Learn
- Possible Media Errors During Backup and Restore (SQL Server), Microsoft Learn
- DBCC CHECKDB (Transact-SQL), Microsoft Learn
Coming soon: Automatic test restores for SQL Server
Prove your SQL Server backups really restore. A backup you have never restored is a hope, not a backup. This planned Windows tool restores each of your SQL Server backups to a scratch database, runs DBCC CHECKDB on the result, and reports pass or fail and how long the restore took. It is designed to run next to your own backups, so nothing large is uploaded to SGU. It is an idea we are gauging interest in; it is not built yet.
Get Automatic test restores for SQL Server first
Join the list and get 25% off your first purchase when it goes on sale. We email you a discount code on launch day. One code per person, for new customers.
One email when it launches (plus the discount code). No other mail, and you can say stop at any time. See our privacy policy.