Maintenance Plan history

I have been researching for the last couple of weeks a way to acquire a maintenance plan job history, success or failure.

After alot of searching and finding that no one has or is not sharing the ability to do this, I decided to start hacking away at the MS SQL 2005/2008 core databases to find the relationship.

After much digging, there are a total of 4 tables you need to have access to, whether through a proxy account of dbo schema account.

Tables in question:
- msdb..sysmaintplan_log
- msdb..sysmaintplan_logdetail
- msdb..sysmaintplan_subplans
- msdb..sysjobs (optional: gives the SQL Agent Job name)

SQL Script as i built it, but you will probably modify it to your needs:
1:  SELECT   
2:     mpld.server_name,  
3:     j.name,  
4:     mpl.start_time,  
5:     mpl.end_time,  
6:     mpl.succeeded,  
7:     mpld.error_number,  
8:     mpld.error_message,  
9:     mpld.line1 + char(10) + char(13) +  
10:        mpld.line2 + char(10) + char(13) +  
11:        mpld.line3 + char(10) + char(13) +  
12:        mpld.line4 + char(10) + char(13) +  
13:        mpld.line5 as details  
14:  FROM msdb..sysmaintplan_log mpl  
15:     inner join msdb..sysmaintplan_logdetail mpld   
16:           on mpl.task_detail_id = mpld.task_detail_id  
17:     inner join msdb..sysmaintplan_subplans mpsp   
18:           on mpl.subplan_id = mpsp.subplan_id  
19:        inner join msdb..sysjobs j   
20:              on mpsp.job_id = j.job_id  
21:  where mpl.start_time between dateadd(day, -7, '5/2/2011') and '5/2/2011'  
22:  order by mpl.end_time desc  

As you can see, this only shows the logdetail entries from (5/2/2011 -7days) to 5/2/2011, which is in effect a range from 4/25/2011 00:01 (or 00:00:001) to 5/1/2011 00:00.

Comments

Popular posts from this blog

SysInternals - BgInfo for ALL Users

JSON/AJAX Helpers

Acquiring List of controls - Classic JS