Email on long running job

PowerShell script exchange

Email on long running job

Veeam Logoby crichardson » Tue Sep 02, 2014 12:59 pm

Every couple of months, typically over a weekend, my Veeam jobs will get stuck at 0%. I have no idea why this happens and Veeam Support has pointed me to this article: http://www.veeam.com/kb1727. The problem is when this happens - on a weekend. I don't find out until Monday (or with Today's case, Tuesday because of the holiday). We're still trying to determine why it's happening.

What I'd like to know is how I could script something simple that will check all the current running jobs to see if they have been running longer than 8 hours. I'll schedule the script to run every hour. If there is a job running longer than 8 hours, I want it to email me with the job name.

Is this possible? Thanks.
crichardson
Enthusiast
 
Posts: 39
Liked: never
Joined: Thu Dec 09, 2010 1:25 pm
Full Name: Corey

Re: Email on long running job

Veeam Logoby v.Eremin » Tue Sep 02, 2014 1:08 pm

Hi Corey, do you have Veeam ONE deployed? If so, you can use one of its alarms that will notify you, if job exceeds allocated time interval. Thanks.
v.Eremin
Veeam Software
 
Posts: 13285
Liked: 971 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Email on long running job

Veeam Logoby crichardson » Tue Sep 02, 2014 1:17 pm

v.Eremin wrote:Hi Corey, do you have Veeam ONE deployed? If so, you can use one of its alarms that will notify you, if job exceeds allocated time interval. Thanks.


I do not. I assume that's only available in the full version of Veeam ONE?
crichardson
Enthusiast
 
Posts: 39
Liked: never
Joined: Thu Dec 09, 2010 1:25 pm
Full Name: Corey

Re: Email on long running job

Veeam Logoby v.Eremin » Tue Sep 02, 2014 3:34 pm

Yes, job duration alarm is shipped in paid version of Veeam ONE. As to PS, you should write something like this:

Code: Select all
$Date = Get-Date
$Jobs = Get-VBRJob | where {$_.Getlaststate() -eq "Working"}
Foreach ($Job in $Jobs){
if (($Date - ($Job.FindLastSession().CreationTime)).hours -ge 8){
$Job | Stop-VBRJob
}
}

Thanks.
v.Eremin
Veeam Software
 
Posts: 13285
Liked: 971 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Email on long running job

Veeam Logoby crichardson » Tue Sep 02, 2014 7:22 pm

I couldn't figure out how to query for running jobs. It's "working". Thanks!
crichardson
Enthusiast
 
Posts: 39
Liked: never
Joined: Thu Dec 09, 2010 1:25 pm
Full Name: Corey

Re: Email on long running job

Veeam Logoby v.Eremin » Wed Sep 03, 2014 8:50 am

And if you want just to have notification, not immediately stop a long running job, then, replace "stopping" part with something that has to with email creation. Thanks.
v.Eremin
Veeam Software
 
Posts: 13285
Liked: 971 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin


Return to PowerShell



Who is online

Users browsing this forum: No registered users and 6 guests