Today I wanted to share on this blog a simple but yet very powerfull SQL Server command RESTORE VERIFYONLY.

Syntax:
[sql]
RESTORE VERIFYONLY FROM DISK = ‘<<location of database backup>>’
[/sql]

This command can be used to check weather your database backup is corrupted.

In order to explain this, I have taken backup of one of my database.
I also made another copy of database backup and I intentionally corrupted it.

DatabaseBackup.BAK is the perfect database backup.
DatabaseBackupCorrupted.BAK is the corrupted database backup.

So First I issued RESTORE VERIFYONLY command on the perferct database backup.
Following is the Query:
[sql]
RESTORE VERIFYONLY FROM DISK = ‘C:DatabaseBackupsDatabaseBackup.BAK’
[/sql]

Output:
The backup set on file 1 is valid.

There were no errors and this made me confirm that the database backup is perfect.

Now I issued the same command on the corrupted database backup.
[sql]
RESTORE VERIFYONLY FROM DISK = ‘C:DatabaseBackupsDatabaseBackupCorrupted.BAK’
[/sql]

As we expect the command errored out with the following error.

Output:

Msg 3242, Level 16, State 2, Line 1
The file on device ‘C:DatabaseBackupsDatabaseBackupCorrupted.BAK’ is not a valid Microsoft Tape Format backup set.
Msg 3013, Level 16, State 1, Line 1
VERIFY DATABASE is terminating abnormally.

There this error output confirms me that the database backup is corrupted.

When ever restoration of a database backup is failing we can use the RESTORE VERIFYONLY command on the back up set and verify it.

Note:
You get the error Operating system error 2(The system cannot find the file specified) when the file cannot be found on the file system. In order to fix it give the correct file name and file path.

Msg 3201, Level 16, State 2, Line 1 Cannot open backup device
‘C:DatabaseBackupsDatabaseBackupCorrupted1.BAK’. Operating system error 2(The system cannot find the file specified.).
Msg 3013, Level 16, State 1, Line 1
VERIFY DATABASE is terminating abnormally.

I got the above error when I issued the following command:
[sql]
RESTORE VERIFYONLY FROM DISK = ‘C:DatabaseBackup.BAK’
[/sql]
As the file C:DatabaseBackup.BAK does not exists.

Hope this posts helps!!!

Related post:
The media family on device is incorrectly formed. SQL Server cannot process this media family Error: 3241

2 Replies to “Verify SQL Server Database Backup”

Leave a Reply

Your email address will not be published. Required fields are marked *