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.
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.
-- 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
SELECT * FROM restorehistory ORDER BY restore_history_id DESC