January 31, 2004 at 5:24 pm
We have many, many jobs scheduled to run in SQL Agent.
It is becoming a common problem that we want to arrange downtime, and some job that was due to run at X o'Clock failed to run because we had the server down. Not that we have downtime that often, but that when we do have it, it is getting increasingly difficult to ensure that we do not miss some job's scheduled time.
Unlike most job scheduling systems, SQL Agent appears, if you miss one scheduled run time, to simply wait for the next. It doesn't run "late" when it comes back.
Has anyone else found this to be a problem, and more significantly has anyone got a script handy that could be periodically run to see if a job missed its scheduled run?
February 2, 2004 at 12:49 am
Maybe you can get on the road with this :
(its a script I use to gather backup-job-info)
-- alzdba dd 08/01/2004
-- request Backup-job info
set nocount on
-- check BOL
select substring(case server
when '(local)' then @@servername
else server
end, 1, 30) as Server
, JobName
, last_run_date
, last_run_time
, Sum_last_run_duration
, freq_type
, frequence
, Units_freq_subday_interval
, freq_subday_interval
, freq_relative_interval
, freq_recurrence_factor
from
(
select substring( J.originating_server , 1, 30) as server
,substring(J.name, 1, 30) as JobName
,min(RIGHT(JS.last_run_date+1000000000000000000,8)) as last_run_date
,min(RIGHT(JS.last_run_time+1000000000000000000,6)) as last_run_time
,sum(JS.last_run_duration) as Sum_last_run_duration
, min( case S.freq_type
when 1 then 'Once'
when 4 then 'Daily'
when 8 then 'Weekly'
when 16 then 'Monthly'
when 32 then 'Monthly*'
when 64 then 'At SqlServer Start'
else '??????'
end ) as freq_type
, min(case S.freq_type
when 1 then convert(varchar(20),S.freq_interval)
when 4 then convert(varchar(20),S.freq_interval)
when 8 then case when convert(binary(2),S.freq_interval ) & 1 = 1 then 'Su-'
else '..-' end
+ case when convert(binary(2),S.freq_interval ) & 2 = 2 then 'Mo-'
else '..-' end
+ case when convert(binary(2),S.freq_interval ) & 4 = 4 then 'Tu-'
else '..-' end
+ case when convert(binary(2),S.freq_interval ) & 8 = 8 then 'We-'
else '..-' end
+ case when convert(binary(2),S.freq_interval ) & 16 = 16 then 'Th-'
else '..-' end
+ case when convert(binary(2),S.freq_interval ) & 32 = 32 then 'Fr-'
else '..-' end
+ case when convert(binary(2),S.freq_interval ) & 64 = 64 then 'Sa'
else '..' end
when 16 then convert(varchar(20),S.freq_interval)
when 32 then case when convert(binary(2),S.freq_interval ) & 1 = 1 then 'Su-'
else '..-' end
+ case when convert(binary(2),S.freq_interval ) & 2 = 2 then 'Mo-'
else '..-' end
+ case when convert(binary(2),S.freq_interval ) & 3 = 3 then 'Tu-'
else '..-' end
+ case when convert(binary(2),S.freq_interval ) & 4 = 4 then 'We-'
else '..-' end
+ case when convert(binary(2),S.freq_interval ) & 5 = 5 then 'Th-'
else '..-' end
+ case when convert(binary(2),S.freq_interval ) & 6 = 6 then 'Fr-'
else '..-' end
+ case when convert(binary(2),S.freq_interval ) & 7 = 7 then 'Sa'
else '..' end
+ case when convert(binary(2),S.freq_interval ) & 8 = 8 then 'Day-'
else '...' end
+ case when convert(binary(2),S.freq_interval ) & 9 = 9 then 'Weekday-'
else '..' end
+ case when convert(binary(2),S.freq_interval ) & 10 = 10 then 'Weekend'
else '..' end
when 64 then convert(varchar(20),S.freq_interval) + ' ???'
else '??????'
end ) as frequence
,min(case S.freq_subday_type
when 1 then 'At the specified time'
when 2 then 'Seconds'
when 4 then 'Minutes'
when 8 then 'Hours'
else '???'
end ) as Units_freq_subday_interval
, min(S.freq_subday_interval) as freq_subday_interval
, min(case S.freq_type
when 32 then case freq_relative_interval --int Scheduled job's occurrence of the freq_interval in each month when freq_type is 32 (monthly relative):
when 1 then 'First'
when 2 then 'Second'
when 4 then 'Third'
when 8 then 'Fourth'
when 16 then 'Last'
else '???'
end
else '-NA-'
end ) as freq_relative_interval
, min(S.freq_recurrence_factor) as freq_recurrence_factor
from msdb.dbo.sysjobs J
inner join msdb.dbo.sysjobsteps JS
on J.job_id = JS.job_id
and JS.command like '%backup%'
and J.enabled = 1
inner join msdb.dbo.sysjobschedules S
on J.job_id = S.job_id
and S.enabled = 1
group by J.originating_server , J.name
) GroupSel
order by JobName
Johan
Learn to play, play to learn !
Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere :w00t:
- How to post Performance Problems
- How to post data/code to get the best help[/url]
- How to prevent a sore throat after hours of presenting ppt
press F1 for solution, press shift+F1 for urgent solution 😀
Need a bit of Powershell? How about this
Who am I ? Sometimes this is me but most of the time this is me
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply