SQL SERVER – Log Shipping Restore Job Error: The file is too recent to apply to the seconda...

来源:转载

If you are a DBA and handled Log-shipping as high availability solution, there are a number of common errors that come that you would over a period of time become pro on resolving. Here is one of the common error which you must have seen:

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:

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 3 rd 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.

<span>-- Assign the database name to variable below<br /> </span><span>DECLARE </span><span>@db_name </span><span>VARCHAR</span><span>(</span><span>100</span><span>)<br /> </span><span>SELECT </span><span>@db_name </span><span>= </span><span>'LSDemo'<br /> </span><span>-- query<br /> </span><span>SELECT TOP </span><span>(</span><span>30</span><span>) </span><span>s.database_name<br /> </span><span>,</span><span>m.physical_device_name<br /> </span><span>,</span><span>CAST</span><span>(</span><span>CAST</span><span>(</span><span>s.backup_size </span><span>/ </span><span>1000000 </span><span>AS INT</span><span>) </span><span>AS VARCHAR</span><span>(</span><span>14</span><span>)) + </span><span>' ' </span><span>+ </span><span>'MB' </span><span>AS </span><span>bkSize<br /> </span><span>,</span><span>CAST</span><span>(</span><span>DATEDIFF</span><span>(</span><span>second</span><span>, </span><span>s.backup_start_date</span><span>, </span><span>s.backup_finish_date</span><span>) </span><span>AS VARCHAR</span><span>(</span><span>4</span><span>)) + </span><span>' ' </span><span>+ </span><span>'Seconds' </span><span>TimeTaken<br /> </span><span>,</span><span>s.backup_start_date<br /> </span><span>,</span><span>CAST</span><span>(</span><span>s.first_lsn </span><span>AS VARCHAR</span><span>(</span><span>50</span><span>)) </span><span>AS </span><span>first_lsn<br /> </span><span>,</span><span>CAST</span><span>(</span><span>s.last_lsn </span><span>AS VARCHAR</span><span>(</span><span>50</span><span>)) </span><span>AS </span><span>last_lsn<br /> </span><span>,</span><span>CASE </span><span>s.[type]<br /> </span><span>WHEN </span><span>'D'<br /> </span><span>THEN </span><span>'Full'<br /> </span><span>WHEN </span><span>'I'<br /> </span><span>THEN </span><span>'Differential'<br /> </span><span>WHEN </span><span>'L'<br /> </span><span>THEN </span><span>'Transaction Log'<br /> </span><span>END AS </span><span>BackupType<br /> </span><span>,</span><span>s.server_name<br /> </span><span>,</span><span>s.recovery_model<br /> </span><span>FROM </span><span>msdb.dbo.backupset s<br /> </span><span>INNER JOIN </span><span>msdb.dbo.backupmediafamily m </span><span>ON </span><span>s.media_set_id </span><span>= </span><span>m.media_set_id<br /> </span><span>WHERE </span><span>s.database_name </span><span>= </span><span>@db_name<br /> </span><span>ORDER BY </span><span>backup_start_date </span><span>DESC<br /> </span><span>,</span><span>backup_finish_date<br /> </span>

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.

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.

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 ( http://blog.sqlauthority.com )



分享给朋友:
您可能感兴趣的文章:
随机阅读: