【问题标题】:How to handle restore fails in log shipping in SQL server 2008 R2?如何处理 SQL Server 2008 R2 中的日志传送恢复失败?
【发布时间】:2017-01-11 12:53:02
【问题描述】:

我正在以待机模式将日志从主 Server1(sql server 2008 R2) 传送到辅助 Server2(sql server 2008 R2)。

所以有 3 个工作:

  • 在 server1 上备份,
  • 复制,
  • 在 server2 上恢复。

备份源和目标的路径在 server2 上,没有文件夹访问问题。

现在第一个作业运行并创建备份,第二个作业创建副本和还原。 第一次一切正常,但我将它们安排为 5 分钟、7 分钟和 9 分钟。

但它在第二次尝试时无法正常工作,即使我手动运行它,恢复作业也会抛出以下错误:

The restore operation completed with errors. Secondary ID: 
could not find a log backup file that could be applied to secondary database.

这是因为主服务器上还有一个日志备份吗?如果是,那么我该如何管理日志备份(外部日志备份和日志传送)。

【问题讨论】:

    标签: sql-server


    【解决方案1】:
    Message
    2015-10-13 21:09:05.13     *** Error: The file ‘C:\LS_S\LSDemo_20151013153827.trn’ is too recent to apply to the secondary database ‘LSDemo’.(Microsoft.SqlServer.Management.LogShipping) ***
    2015-10-13 21:09:05.13     *** Error: The log in this backup set begins at LSN 32000000047300001, which is too recent to apply to the database. An earlier log backup that includes LSN 32000000047000001 can be restored.
    RESTORE LOG is terminating abnormally.(.Net SqlClient Data Provider) ***
    Above error is a shown in failure of the history of restore job. If the failure is more than configured thresholds, then we would start seen below error in SQL ERRORLOG on secondary also:
    2015-10-14 06:22:00.240 spid60       Error: 14421, Severity: 16, State: 1.
    2015-10-14 06:22:00.240 spid60       The log shipping secondary database PinalServer.LSDemo has restore threshold of 45 minutes and is out of sync. No restore was performed for 553 minutes. Restored latency is 4 minutes. Check agent log and logshipping monitor information.
    
    To start troubleshooting, we can look at Job activity monitor on secondary which would fail with the below state:
    
    SQL SERVER - Log Shipping Restore Job Error: The file is too recent to apply to the secondary database LS-Restore-01 
    
    If you know SQL transaction log backup basics, you might be able to guess the cause. If we look closely to the error, it talks about LSN mismatch. Most of the cases, a manual transaction log backup was taken. I remember few scenarios where a 3rd party tool would have taken transaction log backup of database which was also part of a log shipping configuration.
    
    Since we know the cause now, what we need to figure out is – where is that “out of band” backup? Here is the query which I have written on my earlier blog.
    
    -- Assign the database name to variable below
    DECLARE @db_name VARCHAR(100)
    SELECT @db_name = 'LSDemo'
    -- query
    SELECT TOP (30) s.database_name
    ,m.physical_device_name
    ,CAST(CAST(s.backup_size / 1000000 AS INT) AS VARCHAR(14)) + ' ' + 'MB' AS bkSize
    ,CAST(DATEDIFF(second, s.backup_start_date, s.backup_finish_date) AS VARCHAR(4)) + ' ' + 'Seconds' TimeTaken
    ,s.backup_start_date
    ,CAST(s.first_lsn AS VARCHAR(50)) AS first_lsn
    ,CAST(s.last_lsn AS VARCHAR(50)) AS last_lsn
    ,CASE s.[type] WHEN 'D'
    THEN 'Full'
    WHEN 'I'
    THEN 'Diff`enter code here`erential'
    WHEN 'L'
    THEN 'Transaction Log'
    END AS BackupType
    ,s.server_name
    ,s.recovery_model
    FROM msdb.dbo.backupset s
    INNER JOIN msdb.dbo.backupmediafamily m ON s.media_set_id = m.media_set_id
    WHERE s.database_name = @db_name
    ORDER BY backup_start_date DESC
    ,backup_finish_date
    
    Once we run the query, we would get list of backups happened on the database. This information is picked from MSDB database.
    
    Below picture is self-explanatory.
    
    SQL SERVER - Log Shipping Restore Job Error: The file is too recent to apply to the secondary database LS-Restore-02 
    
    Once we found the “problematic” backup, we need to restore it manually on secondary database. Make sure that we are using either norecovery or standby option so that other logs can be restored. Once file is restored, the restore job would be able to pick-up from the same place and would catch up automatically.
    
        enter code here
    
    What are the other problems you have seen with Log-shipping? If you can share some of the common errors, it would be of great help for others and I will try to blog about them too with your help.
    
    Reference: Pinal Dave (https://blog.sqlauthority.com)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-18
      • 1970-01-01
      • 1970-01-01
      • 2013-11-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多