SQL Server 2008 中的差异备份;可以通过 SSMS 恢复,但无法通过 Transact 恢复 SQL

Differential Backups in SQL Server 2008; Able to restore through SSMS but unable to restore through Transact SQL

我在从差异备份恢复数据库时遇到问题。这是我执行的步骤

DROP DATABASE DBName_delta
GO
BACKUP DATABASE DBName TO DISK = 'E:\Fullbak1.bak' 
GO
RESTORE FILELISTONLY FROM DISK = 'E:\Fullbak.bak'
GO
RESTORE DATABASE DBName_delta  
    FROM  DISK='E:\Fullbak.bak' 
   WITH MOVE 'DBName_Data' TO 'E:\DBData\DBName_delta.mdf',   
   MOVE 'DBName_Image_Data' TO 'E:\DBData\DBName_delta_Image_Data.mdf',   
   MOVE 'DBName_Log' TO 'D:\DBLog\DBName_delta.ldf',
   NORECOVERY

--Made Some changes in the database
BACKUP DATABASE DBName
   TO DISK = 'E:\DiffBak1.TRN'
   WITH DIFFERENTIAL
GO

--Made Some more changes in the database    
BACKUP DATABASE DBName
   TO DISK = 'E:\DiffBak2.TRN'
   WITH DIFFERENTIAL
GO

RESTORE FILELISTONLY FROM DISK = 'E:\DiffBak1.TRN'
GO

RESTORE LOG DBName_delta FROM DISK='E:\DiffBak1.TRN' WITH NORECOVERY
GO

Msg 4305, Level 16, State 1, Line 2
The log in this backup set begins at LSN 81125000000059600297, which is too recent to apply to the database. An earlier log backup that includes LSN 81121000000116200001 can be restored.

Msg 3013, Level 16, State 1, Line 2
RESTORE LOG is terminating abnormally.

RESTORE FILELISTONLY FROM DISK = 'E:\DiffBak2.TRN'
GO
RESTORE LOG DBName_delta FROM DISK='E:\DiffBak2.TRN' WITH STANDBY = 'c:\undo.ldf'
GO

但是,当我尝试使用 WITH NORECOVERY 选项通过 SSMS 恢复相同的 E:\DiffBak1.TRN 时,它恢复了数据库,我再次能够使用 Transact 执行相同文件的恢复SQL。我在这里错过了什么吗?这与 RESTORE DATABASE 有关吗?我确信我们不会遗漏中间的任何日志。任何帮助将不胜感激。

我能解决这个问题。正如我提到的,我能够通过 SSMS 向导恢复差异数据库,我从向导中获取脚本并找出查询中的差异。

我使用的是下面的代码

RESTORE LOG DBName_delta FROM DISK='E:\DiffBak1.TRN' WITH NORECOVERY
GO

我已将代码更改为

RESTORE DATABASE [DBrel02t_delta] FROM  DISK = N'E:\DiffBak1.TRN' WITH  FILE = 1,  NORECOVERY,  NOUNLOAD,  STATS = 10
GO

这解决了问题。使用以下查询找出备份的 lsn 详细信息。

RESTORE HEADERONLY FROM DISK  = N’<backup file>’;