SQL 日志备份 - “太新,无法应用于数据库”
我有一个相当大的数据库(用于我们的硬件设置),并且正在尝试对其进行镜像。我似乎无法使主数据库和镜像数据库足够接近同步以允许镜像启动。
完整备份大约需要 10 分钟,另外还需要 8 分钟将 BAK 传输到镜像服务器以及另外 10 分钟进行恢复。因此,为了尝试使事情尽可能紧密地结合在一起,我编写了以下脚本:
** 在主数据库上 **
SET NOCOUNT ON
USE master
DECLARE @dbFileName VARCHAR(75)
, @logFileName VARCHAR(75)
SELECT @dbFileName = 'F:\SQL_Backups\RIVFramework_Prod1\Mirror\prod1.mdf.' + CONVERT(VARCHAR(10), GETDATE(), 102) + '.bak' -- formats date in YYYY.MM.DD --
SELECT @logFileName = 'F:\SQL_Backups\RIVFramework_Prod1\Mirror\prod1.ldf.' + CONVERT(VARCHAR(10), GETDATE(), 102) + '.bak' -- formats date in YYYY.MM.DD --
SELECT @dbFileName
SELECT @logFileName
/**
** 1 - Make sure your database is in full recovery mode
**/
ALTER DATABASE RIVFramework_Prod1
SET RECOVERY FULL
/**
** 2 - Backup the database
**/
BACKUP DATABASE RIVFramework_Prod1
TO DISK = @dbFileName
/**
** 3 - Backup the database log
**/
BACKUP LOG RIVFramework_Prod1
TO DISK = @logFileName
SET NOCOUNT OFF
** 复制文件 **
***注意:我更改了主数据库恢复语句以允许日志文件稍后可以正确恢复。改变了
无法恢复,
如果
有替换,没有恢复,
**在镜像上**
SET NOCOUNT ON
USE master
/**
** Restore backup to Mirror server:
** MIRROR SERVER
** 4 - Restore to the mirror database with no recovery option
**/
RESTORE DATABASE RIVFramework_Prod1
FROM DISK = 'F:\XFer\prod1.mdf.2011.06.10.bak'
WITH REPLACE, NORECOVERY, -- You need to have both options in here so the later log file restore works.
MOVE 'RIVFramework_Prod1' TO 'F:\SQL2008\RIVFramework_Prod1.mdf',
MOVE 'CampaignAnalytics' TO 'F:\SQL2008\RivFramework_Prod1_CampaignAnalytics.ndf',
MOVE 'SalesAnalytics' TO 'F:\SQL2008\RivFramework_Prod1_SalesAnalytics.ndf',
MOVE 'RIVFramework_Prod1_log' TO 'G:\SQL2008\RIVFramework_Prod1_log.ldf'
/**
** 5 - Restore the mirror database logs with no recovery
**/
RESTORE LOG RIVFramework_Prod1
FROM DISK = 'F:\XFer\prod1.ldf.2011.06.10.bak'
WITH NORECOVERY
GO
现在,我大约有 30 分钟不同步。所以我这样做:
** 在主数据库上 **
SET NOCOUNT ON
USE master
DECLARE @logFileName VARCHAR(75)
SELECT @logFileName = 'F:\SQL_Backups\RIVFramework_Prod1\Mirror\prod1.ldf.a.' + CONVERT(VARCHAR(10), GETDATE(), 102) + '.bak' -- formats date in YYYY.MM.DD --
SELECT @logFileName
/**
** 1 - Make sure your database is in full recovery mode
**/
ALTER DATABASE RIVFramework_Prod1
SET RECOVERY FULL
/**
** 3 - Backup the database log
**/
BACKUP LOG RIVFramework_Prod1
TO DISK = @logFileName
SET NOCOUNT OFF
** 复制文件 **
** 在镜像上 **
SET NOCOUNT ON
USE master
/**
** 5 - Restore the mirror database logs with no recovery
**/
RESTORE LOG RIVFramework_Prod1
FROM DISK = 'F:\XFer\prod1.ldf.a.2011.06.10.bak'
WITH NORECOVERY
GO
我收到以下错误:
消息 4305,第 16 层,状态 1,第 53 行 此备份集中的日志开始于 LSN 61063000000325800001,这太 最近申请到数据库。一个 包含 LSN 的早期日志备份 61063000000117800001可以恢复。 消息 3013,第 16 层,状态 1,第 53 行 RESTORE LOG 异常终止。
我缺少什么想法吗?
TIA
I have a rather large database (for our hardware setup) and am trying to get Mirroring going on it. I cannot seem to get the Primary and Mirror databases close enough in sync to allow Mirroring to start.
The full backup takes about 10 minutes, plus another 8 minutes to transfer the BAK to the Mirror server and another 10 minutes to restore it. So, to try to get things as close together as I can I have scripted out the following:
** On the Primary **
SET NOCOUNT ON
USE master
DECLARE @dbFileName VARCHAR(75)
, @logFileName VARCHAR(75)
SELECT @dbFileName = 'F:\SQL_Backups\RIVFramework_Prod1\Mirror\prod1.mdf.' + CONVERT(VARCHAR(10), GETDATE(), 102) + '.bak' -- formats date in YYYY.MM.DD --
SELECT @logFileName = 'F:\SQL_Backups\RIVFramework_Prod1\Mirror\prod1.ldf.' + CONVERT(VARCHAR(10), GETDATE(), 102) + '.bak' -- formats date in YYYY.MM.DD --
SELECT @dbFileName
SELECT @logFileName
/**
** 1 - Make sure your database is in full recovery mode
**/
ALTER DATABASE RIVFramework_Prod1
SET RECOVERY FULL
/**
** 2 - Backup the database
**/
BACKUP DATABASE RIVFramework_Prod1
TO DISK = @dbFileName
/**
** 3 - Backup the database log
**/
BACKUP LOG RIVFramework_Prod1
TO DISK = @logFileName
SET NOCOUNT OFF
** Copy the files **
***NOTE: I altered the main database restore statement to allow the log file to be restored later correctly. Changed
WITH NORECOVERY,
to
WITH REPLACE, NORECOVERY,
** On the Mirror **
SET NOCOUNT ON
USE master
/**
** Restore backup to Mirror server:
** MIRROR SERVER
** 4 - Restore to the mirror database with no recovery option
**/
RESTORE DATABASE RIVFramework_Prod1
FROM DISK = 'F:\XFer\prod1.mdf.2011.06.10.bak'
WITH REPLACE, NORECOVERY, -- You need to have both options in here so the later log file restore works.
MOVE 'RIVFramework_Prod1' TO 'F:\SQL2008\RIVFramework_Prod1.mdf',
MOVE 'CampaignAnalytics' TO 'F:\SQL2008\RivFramework_Prod1_CampaignAnalytics.ndf',
MOVE 'SalesAnalytics' TO 'F:\SQL2008\RivFramework_Prod1_SalesAnalytics.ndf',
MOVE 'RIVFramework_Prod1_log' TO 'G:\SQL2008\RIVFramework_Prod1_log.ldf'
/**
** 5 - Restore the mirror database logs with no recovery
**/
RESTORE LOG RIVFramework_Prod1
FROM DISK = 'F:\XFer\prod1.ldf.2011.06.10.bak'
WITH NORECOVERY
GO
Now, I am about 30 minutes out of sync. So I do:
** On the Primary **
SET NOCOUNT ON
USE master
DECLARE @logFileName VARCHAR(75)
SELECT @logFileName = 'F:\SQL_Backups\RIVFramework_Prod1\Mirror\prod1.ldf.a.' + CONVERT(VARCHAR(10), GETDATE(), 102) + '.bak' -- formats date in YYYY.MM.DD --
SELECT @logFileName
/**
** 1 - Make sure your database is in full recovery mode
**/
ALTER DATABASE RIVFramework_Prod1
SET RECOVERY FULL
/**
** 3 - Backup the database log
**/
BACKUP LOG RIVFramework_Prod1
TO DISK = @logFileName
SET NOCOUNT OFF
** Copy the files **
** On the Mirror **
SET NOCOUNT ON
USE master
/**
** 5 - Restore the mirror database logs with no recovery
**/
RESTORE LOG RIVFramework_Prod1
FROM DISK = 'F:\XFer\prod1.ldf.a.2011.06.10.bak'
WITH NORECOVERY
GO
And I am greeted with the following error:
Msg 4305, Level 16, State 1, Line 53
The log in this backup set begins at
LSN 61063000000325800001, which is too
recent to apply to the database. An
earlier log backup that includes LSN
61063000000117800001 can be restored.
Msg 3013, Level 16, State 1, Line 53
RESTORE LOG is terminating abnormally.
Any ideas what I am missing???
TIA
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在第一个脚本中,您仅想要进行完整备份。
在这两个脚本中,不要每次都将恢复设置为完整,而是检查它是否完整,如果没有停止,则您将需要找出谁在更改恢复模式。
在镜像中使用您显示的脚本来恢复完整备份
返回主体并做日志备份
在镜像处用 norecovery 恢复日志。
In the first script you will only want to do a full backup.
In both scripts do not set the recovery to full every time but check if it is in full and if it is not stop, you will then need to figure out who has been changing the recover mode.
At the mirror use the script you showed to restore just the full backup
Return to the prinicpal and do a log backup
At the mirror restore the log with norecovery.