1

I'm setting up a process to back up a SQL Server 2016 database to Azure blob storage and subsequently restore to another server. I'm doing a weekly full back up and hourly differential. The issue I'm having is that the differential will not restore over the full back up.

Back up to Azure:

BACKUP DATABASE [DB_NAME] TO  
URL = 
N'https://DB_BLOBNAME.blob.core.windows.net/livebackup/DB_NAME_FULL.bak'
WITH  CREDENTIAL = N'BackupCred' , FORMAT, INIT, 
NAME = N'DB_NAME_FULL', SKIP, REWIND, NOUNLOAD,  STATS = 10,  COMPRESSION
GO

BACKUP DATABASE [DB_NAME] TO  URL = 
N'https://DB_BLOBNAME.blob.core.windows.net/livebackup/DB_NAME_DIFF.bak' 
WITH CREDENTIAL = N'BackupCred',  DIFFERENTIAL ,
NOFORMAT, NOINIT,  NAME = N'DB_NAME_DIFF', NOSKIP, NOREWIND, NOUNLOAD,  
STATS = 10
GO

I'm using Azcopy to bring the two .bak files down to the local disk, no issues there. Then restoring from Local file system.

DROP DATABASE DB_NAME
GO
RESTORE DATABASE DB_NAME FROM DISK = 
'C:\AzSyncFolders\DB_NAME\DB_NAME_FULL.BAK' WITH NORECOVERY
GO

RESTORE DATABASE DB_NAME FROM DISK = 
'C:\AzSyncFolders\DB_NAME\DB_NAME_DIFF.BAK' WITH RECOVERY
GO

All pretty straightforward stuff, but I'm consistently getting this message.

Msg 3136, Level 16, State 1, Line 8 This differential backup cannot be restored because the database has not been >>restored to the correct earlier state. Msg 3013, Level 16, State 1, Line 8 RESTORE DATABASE is terminating abnormally.

When I do a full and differential back up on the server locally using the same scripts they both restore correctly.

Am I missing anything obvious in my scripts either in the back up or restore?

Definitely no additional full back up between FULL and DIFF

Just using .BAK out of convention, not sure that having the .DIFF extension will make a difference. Will check to see if there are multiples in the .BAK. No multiples in there.

Changed to use INIT, still getting the error.

**** Update **** Apparently there's a third party tool also taking backups to another location. This would seem to be causing my mismatch between the full and diff LSN. Looks like I'm going to have to take more full backups and abandon the use of diffs. Scott Hodgin called it on the first answer. Thanks for all the help.

  • 1
    This sounds like another full backup has been taken between your original full (that you are trying to restore) and the diff you are trying to restore. – Scott Hodgin Apr 16 '18 at 11:42
  • See if you can use the information in Understanding SQL Server Log Sequence Numbers for Backups to verify that the DatabaseBackupLSN value for the differential backup identifies the full database backup that is required in order to apply the differential database backup. – Scott Hodgin Apr 16 '18 at 12:02
  • Any chance there are multiple backup files in DB_NAME_DIFF.bak? And why .bak, not .dff? – Kevin3NF Apr 16 '18 at 12:03
  • 1
    Since the file names for the FULL and DIFF are different, try using INIT on the DIFF BACKUP also. – Scott Hodgin Apr 16 '18 at 13:14
  • As i mentioned in my comment, verify the DatabaseBackupLSN matches the FULL by using RESTORE HEADERONLY. See the post I referenced. – Scott Hodgin Apr 16 '18 at 14:02
1

Most likely, you have multiple Differential backups in your DB_NAME_DIFF.bak file, and the restore is picking one that occurred before the most recent FULL. As I hinted in my comment, and Scott stated in his.

Edit the following to check for multiple files in a backup device:

RESTORE HEADERONLY   
FROM DISK = N'C:\AdventureWorks-FullBackup.bak'   
WITH NOUNLOAD;  
GO 
  • Yes, this may be the root of it. My DatabaseBackupLSN in the DIFF doesn't match the CheckpointLSN in the FULL. How can I check if there are multiples, Restore FILELISTONLY shows only an mdf and ldf? – Harvey Apr 16 '18 at 14:28
  • @Harvey, see edited answer above – Kevin3NF Apr 16 '18 at 14:33
  • Restore Headeronly shows only one row in the diff. – Harvey Apr 16 '18 at 14:43
  • See update to question. – Harvey Apr 16 '18 at 14:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.