检查超过7天未备份的db

SELECT
dbs.[name] AS DatabaseName
FROM    master.sys.databases dbs
where dbs.database_id <> 2
AND dbs.[name] NOT IN
	(	SELECT
		bus.database_name as 'name'
		FROM msdb.dbo.backupset bus
		INNER JOIN msdb.dbo.backupmediafamily bume ON bus.media_set_id = bume.media_set_id
		WHERE
		dbs.database_id <> 2
		AND dbs.is_in_standby = 0
		AND dbs.source_database_id IS NULL
		AND dbs.[state] <> 1
		AND bus.backup_finish_date >= DATEADD(d, -7, GETDATE())

	)

posted on 2016-07-23 13:51  低级程序人员  阅读(150)  评论(0编辑  收藏  举报

导航