{"id":3278,"date":"2015-12-09T08:04:32","date_gmt":"2015-12-09T13:04:32","guid":{"rendered":"https:\/\/academy.sqlbak.com\/?p=3278"},"modified":"2023-10-17T05:19:16","modified_gmt":"2023-10-17T09:19:16","slug":"checksum-and-verifyonly","status":"publish","type":"post","link":"https:\/\/academy.sqlbak.com\/checksum-and-verifyonly\/","title":{"rendered":"CHECKSUM and VERIFYONLY"},"content":{"rendered":"
A database backup process is an integral part of a recovery system. All backups must be operable so that they can be restored at any time. It is recommended to make regular database backups and the majority of SQL Server users actually follow this recommendation. But how can you be sure that you will be able to restore the database from the backups? Sometimes backups can be corrupted. This is why it is useful to test database backups for their integrity. Of course, the best check for any backup is a restore to a server, but there are some other, less radical ways of doing it. Let’s explore CHECKSUM and VERIFYONLY options.<\/p>\n
The checksum is a value calculated from the data page bytes. Equal data pages have equal checksums. To make the checksum recorded on each page of the backup file the “WITH CHECKSUM” option needs to be added to the “BACKUP DATABASE” command.<\/p>\n
Using a CHECKSUM option makes the database backup process longer, but if the database is really large it is better to use the CHECKSUM option and be confident that all pages are written to the disk and ready for the restore process. To check the checksum value use the following SQL Server option:<\/p>\n
The VERIFYONLY \u00a0option does not restore the backup, it only verifies it. The VERIFYONLY performs several checks, such as:<\/p>\n
It is recommended to check the backup file before the restore process with the help of the VERIFYONLY option. If the file is in a proper state the SQLServer will display the following message:<\/p>\n
The backup set on file 1 is valid.<\/pre>\nIf even a single byte is damaged the SQLServer will report the following:<\/p>\n
Msg 3241, Level 16, State 0, Line 5<\/span>\r\nThe media family on device 'd:\\checksum.bak' is incorrectly formed. SQL Server cannot processthis media family.<\/span>\r\nMsg 3013, Level 16, State 1, Line 5<\/span>\r\nVERIFY DATABASE is terminating abnormally.<\/span><\/pre>\n
How to Use CHECKSUM And VERIFYONLY Options<\/h2>\n
Here are some ways how to add CHECKSUM to the database backups and how to check them with the help of the VERIFYONLY option:<\/p>\n
T-SQL<\/h3>\n
Use T-SQL Command\u00a0<\/strong>to work with\u00a0CHECKSUM<\/strong>\u00a0and VERIFYONLY<\/strong>\u00a0options:<\/em><\/p>\n
To make a database backup simply add the “WITH CHECKSUM” clause:<\/p>\n
BACKUP DATABASE<\/span> your_database <\/em>TO DISK<\/span>\u00a0= 'backup_with_checksum.bak'<\/span> WITH<\/span> CHECKSUM<\/span><\/pre>\n
To check the database with the VERIFYONLY option use the following syntax:<\/p>\n
RESTORE VERIFYONLY FROM DISK<\/span> = 'backup_with_checksum.bak'<\/span><\/pre>\n
SQL Server Management Studio<\/strong><\/h3>\n
Another way of using\u00a0CHECKSUM<\/strong>\u00a0and VERIFYONLY<\/strong>\u00a0options is to apply them in\u00a0SQL Server Management Studio (SSMS)<\/strong>:<\/p>\n
For that, you need to right-click on the database you want to backup, select \u201cTasks\u201d, then \u201cBack up\u2026\u201d. In the window that opened select the “Media Options” page and check “Verify backup when finished” and “Perform checksum before writing to media”. Look at the picture below:<\/p>\n
SQLBackupAndFTP<\/h3>\n
If you prefer third-party utilities\u00a0you can also use\u00a0SQLBackupAndFT<\/a>P<\/strong> to set up CHECKSUM<\/strong>\u00a0and VERIFYONLY<\/strong>\u00a0options:<\/p>\n
Just scroll down to the “Backup options” section and check off the “Enable CheckSum” and “Verify After Backup” options.<\/p>\n
<\/p>\n