Restore verifyonly on the last backup

  • Hi ,

    Somebody can Help me :

    I want a script to use 'restore verifyonly' command on the last full backup of my database :blush:

    (get the path of last full backup and use the command restore verifyonly from disk = <backup>

  • I don't know if it's the best way (but its work) :

    DECLARE @backup nvarchar(90);

    SELECT TOP 1 @backup = physical_device_name

    FROM msdb.dbo.backupset b JOIN msdb.dbo.backupmediafamily m

    ON b.media_set_id = m.media_set_id

    WHERE database_name = 'dbsqware_mssql'

    ORDER BY backup_finish_date DESC

    RESTORE VERIFYONLY FROM disk= @backup

  • Just a quick comment on the process, not the query...

    Unless you've taken the full backup WITH CHECKSUM, the verifyonly verifies very little of the backup and can easily verify as valid a backup that won't restore. If you're going to depend on RESTORE VERIFYONLY, you need to ensure that all the backups are taken WITH CHECKSUM, even then it's not 100% certain.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • thank for your comment.

    So there is not a way to verify that it(restore) works (backup with checksum or not)

  • Restore it.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • GilaMonster (3/28/2013)


    Just a quick comment on the process, not the query...

    Unless you've taken the full backup WITH CHECKSUM, the verifyonly verifies very little of the backup and can easily verify as valid a backup that won't restore. If you're going to depend on RESTORE VERIFYONLY, you need to ensure that all the backups are taken WITH CHECKSUM, even then it's not 100% certain.

    If you are using a Maintenance Plan, there is no option to set the WITH CHECKSUM option on for backups.

    SQL Server Books Online (SQL Server 2008 R2) says the following under the BACKUP topic:

    http://msdn.microsoft.com/en-us/library/ms186865(v=sql.105).aspx

    "...

    CHECKSUM

    Enables backup checksums, so that BACKUP can do the following:

    1. Prior to writing a page to the backup media, BACKUP verifies the page (page checksum or torn page), if this information is present on the page.

    2. Regardless of whether page checksums are present, BACKUP generates a separate backup checksum for the backup streams. Restore operations can optionally use the backup checksum to validate that the backup is not corrupted. The backup checksum is stored on the backup media, not on the database pages. The backup checksum can optionally be used at restore time,

    Using backup checksums may affect workload and backup throughput.

    This is the default behavior for a compressed backup.

    ..."

    However, when I run RESTORE HEADERONLY for a compressed backup made with a maintenance plan, the HasBackupChecksums column has a value of 0, which indicates the backup does not have checksums. I guess the Maintenance Plan is explicitly setting the NO_CHECKSUM option. Or Books Online is wrong.

    UPDATE:

    I just looked at a compressed backup that I was made with an explicit backup command, and the RESTORE HEADERONLY HasBackupChecksums column had a value of 0.

    When I added the CHECKSUM option to the backup command, the RESTORE HEADERONLY HasBackupChecksums column had a value of 1.

    It appears that SQL Server 2008 R2 Books Online is incorrect about CHECKSUM being the default for compressed backups.

  • :-)v

  • ag

  • What's the correct tsql syntax [SQL2008 r2] for RESTORE VERIFYONLY ...WITH CHECKSUM ?

    I successfully backed up the follow DB WITH CHECKSUM and I believe I've followed the syntax for this correctly, but I'm not having any luck. If my syntax is wrong i'll gladly accept a knock on the noggin for the correct syntax. Or maybe my syntax is OK and the books online doco is wrong?

    Here's my attempt WITH CHECKSUM:

    RESTORE VERIFYONLY

    FROM

    DISK = 'Z:\foo\bar.bak'

    WITH

    CHECKSUM

    ,STATS = 2

    RESTORE VERIFYONLY FAILED -- [<--from my print stmt]

    @returnCode = 0 -- value of @@ERROR

    @errorNum = 3013 -- value of ERROR_NUMBER()

    @errorMsg = VERIFY DATABASE is terminating abnormally. -- value of ERROR_MESSAGE()

    RETURN @returnCode = 3013.

    Here's the other 'without' CHECKSUM:

    RESTORE VERIFYONLY

    FROM

    DISK = 'Z:\foo\bar.bak'

    WITH

    --CHECKSUM

    STATS = 2

    18 percent processed.

    37 percent processed.

    55 percent processed.

    74 percent processed.

    92 percent processed.

    100 percent processed.

    The backup set on file 1 is valid.

    RESTORE VERIFYONLY SUCCESSFUL. CONTINUING DB [bar] RESTORE. -- [<--from my print stmt]

    @returnCode = 0 -- related postconditions

    @errorNum = 0

    @errorMsg = ''

    Did it do a checksum validation w/o the 'WITH CHECKSUM' supplied? Or did it do this validation w/o the checksum validation? I tend to believe the answers are no, and yes, respectively. It would be nice if someone could confirm or refute this for me too.

    thx

Viewing 9 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic. Login to reply