SQLTeam.com | Weblogs | Forums

Start SQL job with condition


#1

Hi, guys!

Our backup job is set to start every day at midnight. Can you tell me how to insert a step to this job to verify if others jobs are running and based on this:

  • if other job is running, postpone backup job.
  • if no job is running, start backup job.

Sure, I can put into one job more steps but I want to have them separately.

Thanks!


#2

Why would you want to postpone the backup job if other jobs are running? Do you not run the risk that you do not have a "current" backup?


#3

Kristen, I want to postpone if other jobs are running at that moment.

For example, if DBCC CHECKDB job is running and for somehow reasons is not finished until midnight, I would like to postpone backup job...let's say...for a half hour.

Of course, any other maintenance jobs were scheduled to run much earlier before backup starts but I would like this just in case.


#4

Why not just run the backup anyway, whilst CHECKDB is running?

personally I don't see that as a reason to postpone a backup, but I'm happy to learn that there is a reason :slightly_smiling:


#5

:))
I don't mind to have them running same time if this happens. I was thinking not to affect somehow the normal course of events (if I can put it like this).


#6

They will be happy running at the same time. I think if you get "too clever" with scheduling you run the risk that, as other jobs are added over time, that your Backup runs as Second Priority, and then maybe does not run at a predictable time (and then interferes with user activity, meaning that you cannot get a Restore from a backup made at a "good time" during the day), or does not run often enough / fails to run.

I take the view that backup should be First Priority so that there is no chance that "something else" means that on the day when you have a disaster you then find that you don't have good backups to restore from :frowning:


#7

Good arguments, Kristen!

I will drop this idea and focus on some other things.

Thank you.