SQL Server差异备份的备份/还原原理
记住一点:差异备份是基于最后一次完整备份的差异,而不是基于最后一次差异的差异
1-完整备份之后有无对数据库做过修改,如果有,记录数据库的最后LSN(Last LSN)
4-把最后LSN也记录进去备份文件
FirstLSN
LastLSN
CheckpointLSN
DatabaseBackupLSN
DifferentialBaseLSN
BOOTPAGE里只有DifferentialBaseLSN有值
总体来说,差异备份文件里会存放
FirstLSN
LastLSN
CheckpointLSN
DatabaseBackupLSN
DifferentialBaseLSN
(2)活动日志
(3)差异页面
还原过程:
DifferentialBaseLSN作用:要还原差异备份先要还原一个完整备份,使用NORECOVERY选项,再还原差异备份,当还原差异备份的时候,数据库根据差异备份文件里的DifferentialBaseLSN的值跟
数据库BOOTPAGE保存的DifferentialBaseLSN的值进行比较,如果对不上,那么这个差异备份不能还原,另外一个是作为差异备份还原的基准LSN,差异备份文件里的CheckpointLSN如果小于DifferentialBaseLSN
那么也是没有必要还原
1-将页面从差异备份文件里读出来,然后读出页头的LSN号,跟差异备份文件里的CheckpointLSN进行比较,如果大于CheckpointLSN 并小于LastLSN,那么拿出差异备份文件里的活动日志对改页面进行redo和undo
差异备份的缺点
--脚本 SELECT DB_ID('sss')
DBCC fileheader(16) BACKUP DATABASE [sss] TO DISK='c:\sss_full.bak' RESTORE FILELISTONLY FROM DISK ='c:\sss_full.bak'
RESTORE HEADERONLY FROM DISK ='c:\sss_full.bak' 1585000000012200042 --backuplsn
1686000000056400078 --ckpt lsn
1686000000060800001 --last lsn CREATE TABLE tessssss(id INT)
go INSERT tessssss SELECT 1 UNION ALL SELECT 2 BACKUP DATABASE [sss] TO DISK='c:\sss_diff.bak' WITH Differential RESTORE HEADERONLY FROM DISK ='c:\sss_diff.bak'
1686000000056400078 --backuplsn
1686000000056400078 --diff lsn
1686000000065400151 --ckpt lsn
1686000000071800001 --last lsn INSERT tessssss SELECT 3 UNION ALL SELECT 4 BACKUP DATABASE [sss] TO DISK='c:\sss_diff2.bak' WITH Differential RESTORE HEADERONLY FROM DISK ='c:\sss_diff2.bak'
1686000000056400078 --backuplsn
1686000000056400078 --diff lsn
1686000000071900004 --ckpt lsn
1686000000072300001 --last lsn --FirstLSN
--LastLSN
--CheckpointLSN
--DatabaseBackupLSN
--DifferentialBaseLSN
您真的理解了SQLSERVER的日志链了吗?
http://www.cnblogs.com/lyhabc/p/3460272.html