SQL SERVER Detailed Backup Report
1
vote
2
answers
197
views
I need to create a script that gives the report for the following information:
- Backup Job Name
- Databases that have been backed up in the last 24 hours
- Size of each DB backup
- Start time of backup
- End time of backup
- Duration of backup
- Location of the backup files
I need to still include Log backup information, backup size and the location of the backup files stored. Could someone point me in the right direction of how to better my query? Thanks in advance.
What I have tried:
@dbname sysname
SET @dbname = NULL --set this to be whatever dbname you want
SELECT
bup.database_name AS [Database],
bup.server_name AS [Server],
bup.backup_start_date AS [Backup Started],
bup.backup_finish_date AS [Backup Finished]
,CAST((CAST(DATEDIFF(s, bup.backup_start_date, bup.backup_finish_date) AS int))/3600 AS varchar) + ' hours, '
+ CAST((CAST(DATEDIFF(s, bup.backup_start_date, bup.backup_finish_date) AS int))/60 AS varchar)+ ' minutes, '
+ CAST((CAST(DATEDIFF(s, bup.backup_start_date, bup.backup_finish_date) AS int))%60 AS varchar)+ ' seconds'
AS [Total Time]
FROM msdb.dbo.backupset bup
WHERE bup.backup_set_id IN
(SELECT MAX(backup_set_id)
FROM msdb.dbo.backupset
WHERE database_name = ISNULL(@dbname, database_name) --if no dbname, then return all
AND type = 'D' --only interested in the time of last full backup
GROUP BY database_name)
/* COMMENT THE NEXT LINE IF YOU WANT ALL BACKUP HISTORY */
AND bup.database_name IN (SELECT name FROM master.dbo.sysdatabases)
ORDER BY bup.database_name
Asked by sqllover2020
(73 rep)
Dec 23, 2020, 09:47 PM
Last activity: Jun 25, 2025, 07:04 PM
Last activity: Jun 25, 2025, 07:04 PM