SQL恢复备份遇到错误 - his differential backup cannot be restored because the database has not been restored

恢复数据备份时遇到的错误:

"This differential backup cannot be restored because the database has not been restored to the correct earlier state"


可查询备份历史,验证备份文件序列是否正确。在数据库中查询备份历史,可使用来自http://jasonbrimhall.info/2012/11/28/differential-restore-fail/ 的如下脚本:

DECLARE @SQLVer SQL_VARIANT
		,@DBName VARCHAR(128)
		,@NumDays	SMALLINT
 
SET @DBName = 'YourDatabaseNameHere'
;
SET @NumDays = 14
;
SET @SQLVer = SERVERPROPERTY('ProductVersion');
 
SELECT a.database_name,a.backup_start_date
		,b.physical_device_name AS BackupPath
		,a.position
		,a.type
		,a.backup_size/1024/1024 AS BackupSizeMB
		,CASE 
			WHEN CONVERT(INT,LEFT(CONVERT(VARCHAR(12),@SQLVer),2)) < 10 
				THEN 0
				ELSE a.compressed_backup_size/1024/1024 
			END AS CompressedBackMB
	FROM msdb.dbo.backupset a
		INNER JOIN msdb.dbo.backupmediafamily b
			ON a.media_set_id = b.media_set_id
	WHERE a.type IN ('D','I')
		And a.backup_start_date > GETDATE()- @NumDays
		AND a.database_name = ISNULL(@DBName,a.database_name)
	ORDER BY a.database_name,a.backup_start_date;
 
GO

如果已经无法访问原始数据库,只有备份文件,可以使用如下SQL命令,列出备份文件的序列信息:

restore headeronly from disk='C:\Backup\full_backup_1.bak'

restore headeronly from disk='C:\Backup\tlog1.trn'

restore headeronly from disk='C:\Backup\differential_backup_1.bak'

“the First LSN of 1st transaction log to be restored matches the CheckpointLSN in the full database backup. From there onwards, you can determine the serial order such that the LastLSN of T-Log backup 1 matches FirstLSN of T-log backup 2 and so on. This is because Transaction Log backups are sequential in nature.

 

 For differential backups, you can notice that their DatabaseBackupLSN should be the same as the CheckpointLSN in the full database backup.

Also note that as differential backups are cumulative in nature, restoring the latest differential backup (identified by larger CheckpointLSN) will save some time in the Restore process.”


来自:http://blogs.msdn.com/b/sqlserverfaq/archive/2013/05/22/how-do-i-map-a-differential-transaction-log-backup-to-its-full-backup-without-using-msdb.aspx


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值