PowerShell script exchange
Post Reply
pkelly_sts
Veteran
Posts: 600
Liked: 66 times
Joined: Jun 13, 2013 10:08 am
Full Name: Paul Kelly
Contact:

Check if another job is chained after this one?

Post by pkelly_sts »

Is it possible, with Powershell in a post-job script, to check whether there is another Tape job scheduled/chained to run after the currently running/finishing job (the one calling the post-job script)?

Basically I only want the main part of the post-job script to run (stopping BExec services on the tape server) if there isn't another, specific, Veeam tape job scheduled to run right after it? Just wanting to avoid restarting the BExec services only to stop them all again 1 min later.

I'm being a little fussy I guess but it's useful powershell scripting experience anyway :)
pkelly_sts
Veteran
Posts: 600
Liked: 66 times
Joined: Jun 13, 2013 10:08 am
Full Name: Paul Kelly
Contact:

Re: Check if another job is chained after this one?

Post by pkelly_sts » 1 person likes this post

Reading through the forums I just found this bit of code which I think I can make use of and led me to find the "ScheduleOptions" property of "AfterJob", but a quick test reveals that this property remains even if the job is disabled so now I need to detect whether the job is AfterJob AND disabled...
veremin
Product Manager
Posts: 20282
Liked: 2257 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Check if another job is chained after this one?

Post by veremin »

That's the easiest way to check whether a given tape job is enabled or not:

Code: Select all

Asnp VeeamPSSnapin
$TapeJob = Get-VBRTapeJob -Name "Name of your tape job"
$TapeJob.ScheduleOptions.Enabled
Thanks.
pkelly_sts
Veteran
Posts: 600
Liked: 66 times
Joined: Jun 13, 2013 10:08 am
Full Name: Paul Kelly
Contact:

Re: Check if another job is chained after this one?

Post by pkelly_sts »

Thanks, but just knowing a job is enabled isn't quite enough.

A little more detail:

I run two tape jobs to a tape server that also runs BAckup exec (until I'm confident enough to switch to Veeam)

To run a veeam tape job I need to stop BExec services so have written a PRE-JOB script to check if there are any active BExec jobs and, if not, stop the services, otherwise check again in 5 mins, up to an hour)

I also have a POST-JOB script that starts the BExec services again after the Veeam tape job.

All of this works fine, but because I have 2 tape jobs and they must be run in serial (because only 1 tape drive available) I run the second job right after the first job.

So, it would save me a little time, plus be a bit more efficient, if I could know that the second job was chained to the first so I could build logic into the POST-JOB script to say "if there are no other jobs chained to this one, start the services again, otherwise leave them stopped. (Note: my PRE-JOB script only stops running services anyway)

I want to build in this intelligence in case I later run the second job under its own schedule rather than chained, in which case the first job will automatically restart the services when completed.

Hopefully this makes sense?

(It has also been a learning exercise with Powershell which I just don't do much of these days so want to keep my hand in...)
Post Reply

Who is online

Users browsing this forum: No registered users and 18 guests