Home Microsoft SQL Server Script that shows databases without full or log backups

Polls

Who administers your corporate database infrastructure?
 

related links:

Script that shows databases without full or log backups
User Rating: / 0
PoorBest 
Written by Administrator   
Monday, 18 May 2009 12:33

It is very important to know that a backup policy exists for each database and that this policy works properly. Below is the script that checks for full backup existance for each database and log backup existance for bukl-logged/full recovery model database. Full backup start time must be not earlier than 2 weeks before now and log backups - 3 days.

select dbname = d.name, problem = 'no full backup'
from sys.databases d
where state_desc = 'ONLINE'
  and d.name <> 'tempdb'
  and not exists ( select 1
                   from msdb.dbo.backupset s
                   where d.name = s.database_name
                     and s.[type] = 'D'
                     and DATEDIFF(w, s.backup_start_date, GETDATE()) <=2) -- more than 2 weeks from last full backup
union all
select dbname = d.name, problem = 'no log backup'
from sys.databases d
where recovery_model_desc in ('BULK_LOGGED', 'FULL')
  and d.name <> 'model'
  and state_desc = 'ONLINE'
  and not exists ( select 1
                   from msdb.dbo.backupset s
                   where d.name = s.database_name
                     and s.[type] = 'L'
                     and DATEDIFF(d, s.backup_start_date, GETDATE()) <=3) -- more than 3 days from last log backup

 all the backup problems will be reported right away as the output of script execution

Comments (0)

 
DB-staff Remote DBA Services, Powered by DB-Staff 2008