Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
Log in  ::  Register  ::  Not logged in
Home       Members    Calendar    Who's On

Add to briefcase

Backup Automation Expand / Collapse
Posted Thursday, June 20, 2013 7:17 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Yesterday @ 7:22 AM
Points: 245, Visits: 659
Hello Masters!

We have more than 100+ instances across different SQL servers, and currently manually checking whether the backup job failed\success. Now we are planning to automate this monitoring. So need help to know how to know the specific backup job failed ? I little bit know that the backup information stored in system database "msdb", but dont know which table contains that information.

Can anyone let me know what table contains that information ? Or what is the query to find out backup job's status ?
Post #1465679
Posted Thursday, June 20, 2013 7:37 AM



Group: General Forum Members
Last Login: Yesterday @ 6:01 AM
Points: 2,701, Visits: 3,189
You can use the various [dbo].[backup%] tables in the MSDB database to see when backups are made and all other info about the backups.
You can use the [dbo].[sysjobhistory] table to see the history of all (backup)jobs.

If you setup "database mail" you can use this to get an e-mail alert when a job fails.

** Don't mistake the ‘stupidity of the crowd’ for the ‘wisdom of the group’! **
Post #1465697
Posted Thursday, June 20, 2013 7:39 AM

Say Hey Kid

Say Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey Kid

Group: General Forum Members
Last Login: Friday, October 2, 2015 10:31 AM
Points: 710, Visits: 3,314
Have a look at this:

This is also great:

In the end I ended up impleneting my own solution after being inspired by and

This is the query I use to check for backups from previous day:

SELECT @@ServerName as Server_Name, as Database_Name
FROM master..sysdatabases d
LEFT JOIN msdb..backupset b
ON = b.database_name
AND b.backup_start_date = (SELECT MAX(backup_start_date)
FROM msdb..backupset b2
WHERE b.database_name = b2.database_name
AND b2.type IN ('D','I'))
WHERE != 'tempdb'
--AND NOT IN (SELECT db_name FROM dbautility.dbo.db_exclude)
GROUP BY, b.type, b.backup_size
HAVING MAX(ISNULL(DATEDIFF(dd,ISNULL(b.backup_start_date, '01/01/1900'),GETDATE()),0)) > 1

I have an SSIS package which collects this from 25 instances every morning:

and just about the time I get my coffee ready at 9AM I get a report telling me which databases have not been backed up the day before:

I've also got this report for the SQL Agent jobs:

And this is the code I use:

 SELECT  JobServerName = @@ServerName
, JobID = j.job_id
, JobName =
, JobOwner = ISNULL(, 'Unknown')
, JobRunDate = CAST(STR(jh.run_date, 8, 0) + ' ' + LTRIM(STUFF(STUFF(RIGHT(REPLICATE('0', 6)
+ LTRIM(STR(jh.run_time, 6, 0)), 6),
3, 0, ':'), 6, 0, ':')) AS datetime)
, JobStepName = isnull(js.step_name, 'Undefined')
, JobStepSubsystem = isnull(js.subsystem, 'Undefined')
, JobStepResultDescription = CASE jh.run_status
WHEN 0 THEN 'Failed'
WHEN 1 THEN 'Succeeded'
WHEN 2 THEN 'Retry'
WHEN 3 THEN 'Canceled'
WHEN 4 THEN 'In Progress'
ELSE 'Unknown'
STUFF(STUFF(REPLACE(STR(run_duration,6),' ','0'),5,0,':'),3,0,':') as 'Duration'
FROM msdb.dbo.sysjobs AS j
LEFT JOIN msdb.sys.server_principals AS l ON j.owner_sid = l.[sid]
LEFT JOIN msdb.dbo.sysjobhistory AS jh ON j.job_id = jh.job_id
LEFT JOIN msdb.dbo.sysjobsteps AS js ON jh.step_id = js.step_id
AND jh.job_id = js.job_id
WHERE 1 = 1
and not (jh.run_date is not null and js.step_name is null)


It takes a minimal capacity for rational thought to see that the corporate 'free press' is a structurally irrational and biased, and extremely violent, system of elite propaganda.
David Edwards - Media lens

Society has varying and conflicting interests; what is called objectivity is the disguise of one of these interests - that of neutrality. But neutrality is a fiction in an unneutral world. There are victims, there are executioners, and there are bystanders... and the 'objectivity' of the bystander calls for inaction while other heads fall.
Howard Zinn
Post #1465698
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse