Finding the databases which are not backed up for more than 24hours:
set nocount on
create table #backupcheck (columnName varchar(500),backuptype varchar(50))
insert into #backupcheck SELECT
CASE
WHEN ((datediff(day,MAX(msdb.dbo.backupset.backup_finish_date),getdate()) )>1 )
THEN msdb.dbo.backupset.database_name + ' backup is not completed last day and last backup date is '+CONVERT(VARCHAR(100), MAX(msdb.dbo.backupset.backup_finish_date))+''
END AS columnName,
CASE when msdb.dbo.backupset.type='I' then 'incremental backup'
else 'full backup'
END as backuptype
FROM msdb.dbo.backupmediafamily
INNER JOIN msdb.dbo.backupset ON msdb.dbo.backupmediafamily.media_set_id = msdb.dbo.backupset.media_set_id
WHERE msdb..backupset.type in ('D','I')
GROUP BY
msdb.dbo.backupset.database_name ,msdb..backupset.type
ORDER BY
msdb.dbo.backupset.database_name
select columnName+' and backup type is '+backuptype from #backupcheck where columnName is NOT NULL
drop table #backupcheck
set nocount on
create table #backupcheck (columnName varchar(500),backuptype varchar(50))
insert into #backupcheck SELECT
CASE
WHEN ((datediff(day,MAX(msdb.dbo.backupset.backup_finish_date),getdate()) )>1 )
THEN msdb.dbo.backupset.database_name + ' backup is not completed last day and last backup date is '+CONVERT(VARCHAR(100), MAX(msdb.dbo.backupset.backup_finish_date))+''
END AS columnName,
CASE when msdb.dbo.backupset.type='I' then 'incremental backup'
else 'full backup'
END as backuptype
FROM msdb.dbo.backupmediafamily
INNER JOIN msdb.dbo.backupset ON msdb.dbo.backupmediafamily.media_set_id = msdb.dbo.backupset.media_set_id
WHERE msdb..backupset.type in ('D','I')
GROUP BY
msdb.dbo.backupset.database_name ,msdb..backupset.type
ORDER BY
msdb.dbo.backupset.database_name
select columnName+' and backup type is '+backuptype from #backupcheck where columnName is NOT NULL
drop table #backupcheck
No comments:
Post a Comment