PowerShell script to monitor running jobs

PowerShell script exchange

PowerShell script to monitor running jobs

Veeam Logoby Marcel » Wed Aug 10, 2011 9:08 am

Hello,

In my setup I have about 10 backup jobs. I would like to start a HP Data Protector job after the last job finishes. So ideally I would run a post job script which starts the HP Data Protector job. My problem is that when the last Veeam job is completed earlier jobs might still be running.

So I was searching the forum to see if I could find a PowerShell script providing this functionality. I couldn’t find one :) .

Ideas?

Cheers,
Marcel
Influencer
 
Posts: 11
Liked: 1 time
Joined: Wed Aug 10, 2011 8:58 am
Full Name: Marcel Nobel

Re: PowerShell script to monitor running jobs

Veeam Logoby Gostev » Wed Aug 10, 2011 9:16 am

Marcel wrote:So I was searching the forum to see if I could find a PowerShell script providing this functionality. I couldn’t find one :)

That is strange, because I can see all the latest forum searches, and there are no relevant ones :wink:
There are many existing topics with sample scripts querying job status, just search for powershell job status

Also, you may want to check out this sample script for tape backup integration.
Gostev
Veeam Software
 
Posts: 21396
Liked: 2350 times
Joined: Sun Jan 01, 2006 1:01 am
Location: Baar, Switzerland

Re: PowerShell script to monitor running jobs

Veeam Logoby Marcel » Wed Aug 10, 2011 9:57 am

That is strange, because I can see all the latest forum searches, and there are no relevant ones
There are many existing topics with sample scripts querying job status, just search for powershell job status


http://tinyurl.com/44hvsg9 :P
Marcel
Influencer
 
Posts: 11
Liked: 1 time
Joined: Wed Aug 10, 2011 8:58 am
Full Name: Marcel Nobel

Re: PowerShell script to monitor running jobs

Veeam Logoby Marcel » Wed Aug 10, 2011 10:00 am

The scipt you pointed out is not what I'm looking for.
Marcel
Influencer
 
Posts: 11
Liked: 1 time
Joined: Wed Aug 10, 2011 8:58 am
Full Name: Marcel Nobel

Re: PowerShell script to monitor running jobs

Veeam Logoby Gostev » Wed Aug 10, 2011 10:02 am

I understand, this just for your reference, as this is what most people are using.
Regarding querying job status, just search the forum for powershell job status
Gostev
Veeam Software
 
Posts: 21396
Liked: 2350 times
Joined: Sun Jan 01, 2006 1:01 am
Location: Baar, Switzerland

Re: PowerShell script to monitor running jobs

Veeam Logoby Sethbartlett » Wed Aug 10, 2011 7:36 pm

You would want to do something like the following:
Code: Select all
$Job = Get-VBRJob | ?{$_.name -eq "JobName"}
$Job.GetLastState()

You could have this in your script to cycle through all your jobs like the following:
Code: Select all
foreach ($v in (Get-VBRJob)){$v.GetLastState()}

That will cycle through all your jobs and get the latest state.
Skype: Sethbartlett88 - Make sure to label who you are and why you want to add me ;)
Twitter: @sethbartlett
If my post was helpful, please like it. Sometimes twitter is quicker to hit me up if you need me.
Sethbartlett
Expert
 
Posts: 282
Liked: 25 times
Joined: Wed Nov 10, 2010 6:51 pm
Full Name: Seth Bartlett

Re: PowerShell script to monitor running jobs

Veeam Logoby Marcel » Thu Aug 11, 2011 11:21 am

Thank you both for the help. I'm going to write a script for this costumer. If i'm able to produce a usable script I will post it here.

Thanks,
Marcel
Influencer
 
Posts: 11
Liked: 1 time
Joined: Wed Aug 10, 2011 8:58 am
Full Name: Marcel Nobel

Re: PowerShell script to monitor running jobs

Veeam Logoby Marcel » Thu Aug 11, 2011 6:05 pm

This is the script i'm testing now. Seems to be working for me.

Code: Select all
Add-PSSnapin Veeampssnapin
$JobActive=0
Do {
foreach ($v in (Get-VBRJob))
{
   $JobStatus = ($v.GetLastState())
   If ($JobStatus -notlike "Stopped"){$JobActive ++}
}}
while($JobActive -notlike "0")
#Insert backup command here


Would be a nice feature in the next release. A little checkbox in the post job activity screen "Only run when no jobs are running" would be enough for me. :D

Edit: I would be realy nice to have a job chaining feature in the next release. @Veeam please see this as a feature request.
Marcel
Influencer
 
Posts: 11
Liked: 1 time
Joined: Wed Aug 10, 2011 8:58 am
Full Name: Marcel Nobel

Re: PowerShell script to monitor running jobs

Veeam Logoby Gostev » Thu Aug 11, 2011 6:53 pm

Why do you need job chaining, Marcel?
Gostev
Veeam Software
 
Posts: 21396
Liked: 2350 times
Joined: Sun Jan 01, 2006 1:01 am
Location: Baar, Switzerland

Re: PowerShell script to monitor running jobs

Veeam Logoby Sethbartlett » Thu Aug 11, 2011 7:03 pm

We do have "job chaining" so to speak. If you go to properties -> Next until the last page that says "Summary". You can grab the command line string and place it into the "post job" script for another job. From here, one job will kick off another.
Skype: Sethbartlett88 - Make sure to label who you are and why you want to add me ;)
Twitter: @sethbartlett
If my post was helpful, please like it. Sometimes twitter is quicker to hit me up if you need me.
Sethbartlett
Expert
 
Posts: 282
Liked: 25 times
Joined: Wed Nov 10, 2010 6:51 pm
Full Name: Seth Bartlett

Re: PowerShell script to monitor running jobs

Veeam Logoby Marcel » Thu Aug 11, 2011 8:42 pm 1 person likes this post

Ik know the command is in the summary tab, thanks.

I think it would be nice to have chaining in the interface because not all customers are able to create en maintain (powershell) scripts.
Marcel
Influencer
 
Posts: 11
Liked: 1 time
Joined: Wed Aug 10, 2011 8:58 am
Full Name: Marcel Nobel

Re: PowerShell script to monitor running jobs

Veeam Logoby Sethbartlett » Thu Aug 11, 2011 9:21 pm

Chaining jobs together with the command in the summary tab doesn't require any powershell. If you want to make sure other jobs aren't running or special things, then that currently requires powershell:)
Skype: Sethbartlett88 - Make sure to label who you are and why you want to add me ;)
Twitter: @sethbartlett
If my post was helpful, please like it. Sometimes twitter is quicker to hit me up if you need me.
Sethbartlett
Expert
 
Posts: 282
Liked: 25 times
Joined: Wed Nov 10, 2010 6:51 pm
Full Name: Seth Bartlett

Re: PowerShell script to monitor running jobs

Veeam Logoby Gostev » Thu Aug 11, 2011 9:37 pm

Marcel, my question is more about why do you need the ability to chain. I would like to understand your use case behind it. Thanks.
Gostev
Veeam Software
 
Posts: 21396
Liked: 2350 times
Joined: Sun Jan 01, 2006 1:01 am
Location: Baar, Switzerland

Re: PowerShell script to monitor running jobs

Veeam Logoby Marcel » Fri Aug 12, 2011 10:43 am

Anton, maybe chaining isn’t the right word. Let’s call it grouping. Grouping lets us put multiple jobs in a group. One feature of a group is the ability to set a post command after all the jobs in this group are done (regardless of the result).

Another nice feature of a group would be to set (besides a post job command) some of the settings for all the jobs in the group for example VSS credentials, Restore points etc.

You might say “There is a job for, you don’t need group”. When we install Veeam at large customers (200+ vm’s) we need to create multiple jobs. In the past we created one job for a lot of VM’s. We noticed this is not always the best way to go. One reason for this is file corruption. In the past we had file corruption a few times. The only way to resolve this was to create a new full backup. This can take a long time when we are talking about more the 15TB.

I hope the above is clear.
Marcel
Influencer
 
Posts: 11
Liked: 1 time
Joined: Wed Aug 10, 2011 8:58 am
Full Name: Marcel Nobel

Re: PowerShell script to monitor running jobs

Veeam Logoby Gostev » Fri Aug 12, 2011 2:40 pm

Marcel, thanks for the detailed explanation.
Gostev
Veeam Software
 
Posts: 21396
Liked: 2350 times
Joined: Sun Jan 01, 2006 1:01 am
Location: Baar, Switzerland

Next

Return to PowerShell



Who is online

Users browsing this forum: No registered users and 8 guests