SQL Server的差异备份还原

在SQL Server中还原差异备份,需要先还原在差异备份时间点之前的一个完整备份,在还原完整备份时要加上NORECOVERY参数,示例SQL语句如下:

RESTORE DATABASE [数据库名称] 
FROM  DISK = N'完整备份文件路径' 
WITH  FILE = 1,  
NOUNLOAD,  
STATS = 10, 
NORECOVERY
GO

在Management Studio中对应的选项是:

Leave the database non-operational, and do not roll back uncommitted transactions. Additional transaction logs can be restored. (RESTORE WITH NORECOVERY)

如果没有加上NORECOVERY参数,默认是RECOVERY,则:

  • 在SQL Server 2012 Management Studio中通过窗口操作会出现错误提示:Unable to create restore plan due to break in the LSN chain.
  • 在SQL Server 2008/2012 Management Studio中执行SQL语句会出现错误提示:The log or differential backup cannot be restored because no files are ready to rollforward.

(抱怨:提示信息容易误导人)

还原差异备份时,如果只有一个差异备份文件需要还原,无需使用NORECOVERY参数,示例SQL语句如下:

RESTORE DATABASE [数据库名称] 
FROM  DISK = N'差异备份文件路径' 
WITH  FILE = 1,  
NOUNLOAD,  
STATS = 10
GO

如果有多个差异备份文件需要还原,除了最后一个差异备份文件,其他都需要加上NORECOVERY参数。

【参考资料】

SQL Server 备份和还原全攻略

 

    原文作者:sql
    原文地址: https://www.cnblogs.com/dudu/p/sql_server_differential_backup_restore.html
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞