Labels

Monday, 16 May 2016

SQL DBA: Script to find missing log backup

Situation : While performing log shipping failover I got the error like LSN mismatch .

To fix this issue I need to find the missing log backup details.

For this we need to use system tables from master (sysdatabases)  and msdb databases  (backupset and backupmediafamily )

SELECT sd.NAME
 ,bs.TYPE
 ,bs.database_name
 ,bs.backup_start_date AS last_backup
FROM master..sysdatabases sd
LEFT JOIN msdb..backupset bs ON rtrim(bs.database_name) = rtrim(sd.NAME)
LEFT JOIN msdb..backupmediafamily bmf ON bs.media_set_id = bmf.media_set_id
WHERE sd.NAME = 'DBA_Info' -- pass the db name here
 AND bs.backup_start_date > getdate() - 10
ORDER BY sd.NAME
 ,last_backup

2 comments: