RESTORE VERIFYONLY what does WITH LOADHISTORY do?

2

July 18, 2018 by Kenneth Fisher

Recently someone mentioned the LOADHISTORY option of RESTORE. It’s not horribly hard to find in BOL but it wasn’t the easiest thing (at least for me) to understand at first.

LOADHISTORY
Supported by: RESTORE VERIFYONLY

Specifies that the restore operation loads the information into the msdb history tables. The LOADHISTORY option loads information, for the single backup set being verified, about SQL Server backups stored on the media set to the backup and restore history tables in the msdb database. For more information about history tables, see System Tables (Transact-SQL).

So, first of all, it only works with RESTORE VERIFYONLY. RESTORE VERIFYONLY does some basic checking on a backup to make sure that it can be read and understood by SQL. Please note, it does not mean that the backup can be restored. It will check things like the checksum, available diskspace (if you specify a location), the header and that the backup set is actually complete and readable. Basically enough to see if it will start restoring, but it could still have errors later on.

As for what LOADHISTORY actually does? It causes you to write an entry to the restore history table. You can tell which record this is because the restore_type is set to a V. Really, the only benefit here (as I see it) is that you can do reporting on what backups you’ve verified.

Demo
-- Look up he database name, physical_device_name and position
SELECT backupset.database_name, backupmediafamily.physical_device_name,
	backupset.position
FROM backupset 
JOIN backupmediafamily
	ON backupset.media_set_id = backupmediafamily.media_set_id
WHERE backup_set_id= 35
-- Confirm that the database name is correct by checking the header.
RESTORE HEADERONLY FROM DISK = 'C:\backups\backup.bak' WITH FILE = 2
-- Verify the backup and record it to the restore history table.
RESTORE VERIFYONLY FROM DISK = 'C:\backups\backup.bak' WITH LOADHISTORY, FILE = 2


The backup set on file 2 is valid.


SELECT * FROM restorehistory ORDER BY restore_history_id DESC

2 thoughts on “RESTORE VERIFYONLY what does WITH LOADHISTORY do?

  1. […] Kenneth Fisher explains what the LOADHISTORY option means when you run a RESTORE VERIFYONLY comman…: […]

  2. If using TDE and compressed backups, you will want to apply the latest CU for 2016/2017 else risk corrupting your database.

    https://support.microsoft.com/en-us/help/4101502/tde-enabled-database-backup-with-compression-causes-corruption

Leave a Reply to SQL Server Backup Restoration With LOADHISTORY – Curated SQL Cancel reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 3,755 other subscribers

Follow me on Twitter

ToadWorld Pro of the Month November 2013
%d bloggers like this: