patternsqlMinor
SQL Server 2008 R2 Query Last Successful Database Backup For All DBs
Viewed 0 times
dbslast2008successfulallsqlquerydatabaseforserver
Problem
Is it possible to query the last successful backup date (and perhaps the type of backup) of each database in SQL Sever 2008 R2?
Solution
Yes, as long as the history data is still in msdb database. The following block of code will get your the last 100 backups including full, differential and log backups.
SELECT TOP 100
s.database_name,
m.physical_device_name,
CAST(DATEDIFF(second, s.backup_start_date,
s.backup_finish_date) AS VARCHAR(100)) + ' ' + 'Seconds' TimeTaken,
s.backup_start_date,
CASE s.[type]
WHEN 'D' THEN 'Full'
WHEN 'I' THEN 'Differential'
WHEN 'L' THEN 'Transaction Log'
END AS BackupType,
s.server_name,
s.recovery_model
FROM msdb.dbo.backupset s
INNER JOIN msdb.dbo.backupmediafamily m ON s.media_set_id = m.media_set_id
WHERE s.database_name = DB_NAME() -- Remove this line for all the database
ORDER BY backup_start_date DESC, backup_finish_date
GOContext
StackExchange Database Administrators Q#11005, answer score: 7
Revisions (0)
No revisions yet.