SQL – last backup time (db + transaction log)


I don’t normally setup much maintenance plans as developer, but today I had to do some monitoring and troublehooting. During this work, I discovered lots of errors and in the event viewer and large transaction log files on the disk, resulting in low disk space on the production SQL server.

Last backup time for transaction logs:

SELECT   
    d.name,
    MAX(b.backup_finish_date) AS backup_finish_date
FROM  master.sys.sysdatabases d
   LEFT OUTER JOIN msdb..backupset b
      ON       b.database_name = d.name
          AND  b.type = 'L'
GROUP BY d.name
ORDER BY backup_finish_date DESC

Last backup time for databases:

SELECT 
   sdb.Name AS DatabaseName,
   COALESCE(CONVERT(VARCHAR(12), MAX(bus.backup_finish_date), 101),'-') 
      AS LastBackUpTime
 FROM sys.sysdatabases sdb
	LEFT OUTER JOIN msdb.dbo.backupset bus 
		ON bus.database_name = sdb.name
 GROUP BY sdb.Name
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s