黑帽联盟

标题: 用脚本查看数据库最近备份 [打印本页]

作者: 定位    时间: 2017-1-26 16:30
标题: 用脚本查看数据库最近备份
用脚本查看数据库最近备份,脚本如下:
  1. --查看最近一次备份时间
  2. SELECT D.name  AS DatabaseName,
  3. FB.FullBackupTime,
  4. LB.LogBackupTime
  5. FROM master.sys.databases D
  6. INNER JOIN sys.database_mirroring dm
  7. on D.database_id=dm.database_id
  8. AND (dm.mirroring_guid IS NULL OR dm.mirroring_role=1)
  9. LEFT JOIN (
  10. SELECT database_name AS DatabaseName, max(backup_finish_date)  AS FullBackupTime
  11. FROM msdb.dbo.backupset B1
  12. WHERE  B1.type='D'
  13. GROUP BY database_name, [type]) AS FB ON D.name=FB.DatabaseName
  14. LEFT JOIN (
  15. SELECT database_name AS DatabaseName, max(backup_finish_date)  AS LogBackupTime
  16. FROM msdb.dbo.backupset B1
  17. WHERE  B1.type='L'
  18. GROUP BY database_name, [type]) AS LB ON D.name=LB.DatabaseName
  19. WHERE D.database_id>4
复制代码





欢迎光临 黑帽联盟 (https://bbs.cnblackhat.com/) Powered by Discuz! X2.5