SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 

RESTORE VERIFYONLY what does WITH LOADHISTORY do?

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

SQLStudies

My name is Kenneth Fisher and I am Senior DBA for a large (multi-national) insurance company. I have been working with databases for over 20 years starting with Clarion and Foxpro. I’ve been working with SQL Server for 12 years but have only really started “studying” the subject for the last 3. I don’t have any real "specialities" but I enjoy trouble shooting and teaching. Thus far I’ve earned by MCITP Database Administrator 2008, MCTS Database Administrator 2005, and MCTS Database Developer 2008. I’m currently studying for my MCITP Database Developer 2008 and should start in on the 2012 exams next year. My blog is at www.sqlstudies.com.

Comments

Leave a comment on the original post [sqlstudies.com, opens in a new window]

Loading comments...