FULL Backup Failure Reports
FULL Backup Failure Reports
full_latest_backup_details
-- Query to find latest "Full" as well as "T-Log" backup of all specified Databases
-- Query to find latest "Full" as well as "T-Log" backup of all specified Databases
USE DBA
GO
SELECT msdb.dbo.backupset.server_name
,msdb.dbo.backupset.database_name
WHEN 'D'
THEN 'Full'
WHEN 'I'
THEN 'Differential'
WHEN 'L'
WHEN 'F'
WHEN 'G'
WHEN 'P'
THEN 'Partial'
WHEN 'Q'
ELSE msdb.dbo.backupset.[type]
END AS BackupType
, msdb.dbo.backupset.backup_finish_date as Latest_backup_Date
,CAST((CAST(DATEDIFF(s, msdb.dbo.backupset.backup_start_date,
msdb.dbo.backupset.backup_finish_date) AS INT)) / 3600 AS VARCHAR) + ' hours, ' +
CAST((CAST(DATEDIFF(s, msdb.dbo.backupset.backup_start_date,
msdb.dbo.backupset.backup_finish_date) AS INT)) / 60 AS VARCHAR) + ' minutes, ' +
CAST((CAST(DATEDIFF(s, msdb.dbo.backupset.backup_start_date,
msdb.dbo.backupset.backup_finish_date) AS INT)) % 60 AS VARCHAR) + ' seconds' AS
[Total_Time_Taken_For_Backup]
,msdb.dbo.backupmediafamily.physical_device_name AS Backup_File_Location
into dba..full_latest_backup_details
FROM msdb.dbo.backupmediafamily
WHERE (
backup_set_ID IN (
SELECT MAX(backup_set_id)
FROM msdb.dbo.backupset
GROUP BY database_name
OR backup_set_ID IN (
SELECT MAX(backup_set_id)
FROM msdb.dbo.backupset
GROUP BY database_name
) OR
backup_set_ID IN (
SELECT MAX(backup_set_id)
FROM msdb.dbo.backupset
GROUP BY database_name
ORDER BY msdb.dbo.backupset.database_name
,BackupType
GO
go
declare cur1 cursor for SELECT name FROM sys.databases where is_read_only<>1
open cur1
while @@fetch_status=0
begin
open cur
while @@fetch_status=0
begin
print @db14
end
close cur
deallocate cur
end
update
dba..full_latest_backup_details set backup_status='NA' where backup_status='NULL'
close cur1
deallocate cur1
if @var >= 1
begin
<tr>
<th> server_name </th> <th> database_name </th> <th> BackupType </th> <th>
Latest_Backup_date </th><th> Total_Time_Taken_For_Backup </th><th>
Backup_File_Location </th><th> Backup_Status </th></tr>'
EXEC msdb.dbo.sp_send_dbmail
@profile_name='DBA',
@body = @body,
@body_format ='HTML',
@subject = '*IMP* IMMEDIATE ACTION REQUIRED - SQL SERVER DATABASES -FULL BACKUP
FAILURE REPORT ' ;
end