差异备份问题-为什么?这可能吗?


13

我正在使用SQL Server 2014,情况是这样的:

  • 我有服务器A和服务器B。
  • 隔夜ETL在服务器A上处理。
  • 加载过程完成后,将备份数据库X(使用CHECKSUMRESTORE VERIFYONLY确保可靠性),然后将其发送到服务器B。
  • 服务器B接收到该bak文件,然后在那里还原数据库。

我想使用差异备份策略,以便:

  1. 完全备份仅在星期六执行,
    即在星期六在服务器A上进行完全备份->运送到服务器B->恢复服务器B上的完全备份

  2. 剩下的日子将是差异备份,
    即服务器A上的差异备份->运送到服务器B->恢复服务器B上的差异备份

我已经尝试过,但出现错误,说:

日志或差异备份无法还原,因为没有文件准备好前滚。

不知道为什么。我检查sys.database_files了服务器A和服务器B,可以看到differential_Base_LSNdifferential_base_GUID相同。还有其他地方要检查吗?

顺便说一句,在上面的步骤2中,当我在服务器B上还原差异备份时,是否总是需要每次都还原完全备份+差异备份?

我只还原了差异备份WITH RECOVERY(并收到该错误消息),因为完整备份已于前一天还原。

需要说明的是:是的,我希望服务器B上的数据库在差异之间可读。我该如何解决?是我每晚唯一的RESTORE FULL (WITH NORECOVERY)+ RESTORE DIFF (WITH RECOVERY)组合顺序选项吗?

任何指导将不胜感激。

Answers:


15

你并不需要乱用RECOVERYNORECOVERY在这里,所有你需要的是STANDBY选项。这是有关如何使用它的快速演示。

创建一个数据库,将其设置为简单恢复,然后创建一个表。

插入数据,进行一些比较。

好玩吧

USE master;

/*Create a dummy database*/
CREATE DATABASE DiffRestoreTest

/*We simple now*/
ALTER DATABASE DiffRestoreTest SET RECOVERY SIMPLE

/*Context is everything*/
USE DiffRestoreTest

/*If nothing changes, do we even need a diff backup?*/
CREATE TABLE dbo.t1 (Id INT)

/*Take a full backup, dummy*/
BACKUP DATABASE DiffRestoreTest 
TO DISK = 'F:\Backup\DRT_FULL.bak' 
WITH INIT, FORMAT, COMPRESSION

/*Make a change*/
INSERT dbo.t1 (Id )
VALUES ( 1 )

/*Take a differential backup*/
BACKUP DATABASE DiffRestoreTest 
TO DISK = 'F:\Backup\DRT_DIFF_1.bak' 
WITH INIT, FORMAT, COMPRESSION, DIFFERENTIAL

/*Make another change*/
INSERT dbo.t1 (Id )
VALUES ( 2 )

/*Take another diff backup*/
BACKUP DATABASE DiffRestoreTest  
TO DISK = 'F:\Backup\DRT_DIFF_2.bak' 
WITH INIT, FORMAT, COMPRESSION, DIFFERENTIAL

/*Make another change*/
INSERT dbo.t1 (Id )
VALUES ( 3 )

/*Take another diff backup*/
BACKUP DATABASE DiffRestoreTest 
TO DISK = 'F:\Backup\DRT_DIFF_3.bak' 
WITH INIT, FORMAT, COMPRESSION, DIFFERENTIAL

是的,我撒谎了。那是无聊的部分。

您可以在中还原完整备份STANDBY

/*Exit stage left*/
USE master

/*Restore the full backup*/
RESTORE DATABASE DiffRestoreTest
FROM DISK = 'F:\Backup\DRT_FULL.bak' 
WITH REPLACE, STANDBY = 'F:\Backup\DRT_STANDBY.tuf'

您可以按以下顺序恢复Diffs STANDBY

/*Square one*/
RESTORE DATABASE DiffRestoreTest
FROM DISK = 'F:\Backup\DRT_DIFF_1.bak' 
WITH STANDBY = 'F:\Backup\DRT_STANDBY.tuf'

/*Square 2*/
RESTORE DATABASE DiffRestoreTest
FROM DISK = 'F:\Backup\DRT_DIFF_2.bak' 
WITH STANDBY = 'F:\Backup\DRT_STANDBY.tuf'

/*Square 3*/
RESTORE DATABASE DiffRestoreTest
FROM DISK = 'F:\Backup\DRT_DIFF_3.bak' 
WITH STANDBY = 'F:\Backup\DRT_STANDBY.tuf'

与那些讨厌的日志文件不同,在还原Diff时,您也可以跳过:

/*Restore the full backup*/
RESTORE DATABASE DiffRestoreTest
FROM DISK = 'F:\Backup\DRT_FULL.bak' 
WITH REPLACE, STANDBY = 'F:\Backup\DRT_STANDBY.tuf'

/*What happens if I try to jump the restores?*/
RESTORE DATABASE DiffRestoreTest
FROM DISK = 'F:\Backup\DRT_DIFF_3.bak' 
WITH STANDBY = 'F:\Backup\DRT_STANDBY.tuf'

如果要测试可读性,只需在还原命令之间运行它。您应该看到ID每增加一个。如果不这样做,那么您做错了什么。

请记住,还原文件时,它将把所有最终用户踢出数据库,并且不会等待他们的查询完成。

这也使数据库处于只读状态,此处无法进行任何更改。

SELECT * 
FROM DiffRestoreTest.dbo.t1 AS t

最后,自己清理。

/*Bring'er online, lad*/
RESTORE DATABASE DiffRestoreTest WITH RECOVERY

DROP DATABASE DiffRestoreTest

希望这可以帮助!!

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.