Unsuccesful jobs

PowerShell script exchange

Re: Unsuccesful jobs

Veeam Logoby v.Eremin » Tue May 14, 2013 8:35 am

So, are you saying that the names of corresponding VM (“Failed VM/VM with warnings”) in case of “Warning” session are shown correctly, but in case of “Failed” session you get a blank field, instead?

Honestly, I just checked it and everything seemed to work properly. Below you can find the result I got:

Code: Select all
Name                                        Last result Failed VM\VM with warnings Description               
----                                        ----------- -------------------------- -----------               
Replication Job 4                                Failed {Win7_migrated, Win7_mi... Created by V65\Administ...
Backup Job 3                                     Failed {Win8n3, Win8n2, Win8n4}   Custom description   


Anyway, what if you modify the aforesaid code a little bit, creating different “Warning” function responsible for listing only “Warning” sessions, separating it from "Failed" function, and changing slightly body of the script?

Code: Select all
asnp VeeamPSSnapin
Function Failed([Veeam.Backup.Core.CBackupJob]$Job)
{
  $Sessions = Get-VBRBackupSession -name $Job.name | ?{$_.CreationTime -ge (Get-Date).addhours(-24)}
  foreach ($session in $Sessions)
  {
     $session.Gettasksessions() | ? {$_.Status -eq "Failed"}
  }
}
Function Warning([Veeam.Backup.Core.CBackupJob]$Job)
{
  $Sessions = Get-VBRBackupSession -name $Job.name | ?{$_.CreationTime -ge (Get-Date).addhours(-24)}
  foreach ($session in $Sessions)
  {
     $session.Gettasksessions() | ? {$_.Status -eq "Warning"}
  }
}
Get-VBRJob | ? {($_.Info.ScheduleOptions.LatestRun -ge (Get-Date).addhours(-24)) -and (($_.GetLastResult() -eq "Warning") -or ($_.GetLastResult() -eq "Failed"))} | Select-Object -Property @{N="Name";E={$_.Name}} ,@{N="Last result";E={$_.GetLastResult()}}, @{N="Failed VM";E={(Failed $_).name}} ,@{N="VM with warning";E={(Warning $_).name}}, @{N="Description";E={$_.Description}} | Sort Name -Descending | Format-Table


Hope this helps.
Thanks.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Unsuccesful jobs

Veeam Logoby v.Eremin » Tue May 14, 2013 8:39 am

Hi Vladimir,
great work... I added a link to the "Getting Started and Code Examples " section.
Thank you ... Andy

I’m wondering whether everything works as expected in your environment, or you’re facing the similar issue as Magnus with the VM names not being shown correctly.

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

Re: Unsuccesful jobs

Veeam Logoby masonit » Tue May 14, 2013 11:36 am

v.Eremin wrote:So, are you saying that the names of corresponding VM (“Failed VM/VM with warnings”) in case of “Warning” session are shown correctly, but in case of “Failed” session you get a blank field, instead?


Exact!

I tried the the other script but I got the same problem with that:

Last result Failed VM VM with warning
Warning prodapptok01
Warning DRSTEAP07
Failed

I am using VBR 6.5.0.128 with powershell 3.0.

\Masonit
masonit
Service Provider
 
Posts: 141
Liked: 10 times
Joined: Tue Oct 09, 2012 2:30 pm
Full Name: Magnus Andersson

Re: Unsuccesful jobs

Veeam Logoby v.Eremin » Tue May 14, 2013 11:53 am

Can you confirm that, at least, one VM has failed during last session?

It can be the means of the following script:

Code: Select all
Asnp VeeamPSSnapin
Function Failed([Veeam.Backup.Core.CBackupJob]$Job)
{
  $Sessions = Get-VBRBackupSession -name $Job.name | ?{$_.CreationTime -ge (Get-Date).addhours(-24)}
  foreach ($session in $Sessions)
  {
     $session.Gettasksessions() | ? {$_.Status -eq "Failed"}
  }
}
$Job = Get-VbrJob -name "Name of your job"
Failed $Job | Select name


If as the result of this script execution you get blank list, it means that no VM has failed during last backup session.

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

Re: Unsuccesful jobs

Veeam Logoby masonit » Tue May 14, 2013 12:20 pm

v.Eremin wrote:Can you confirm that, at least, one VM has failed during last session?


I can not run that script. I get "VeeamPSS is not installed on this computer".

I have just created two test jobs that has failed. I see them both but not the VMs:

Code: Select all
Name                                                                   Last result Failed VM\VM with warnings               Description
Backup Job 104                                                              Failed                                          Created by * at 2013-05-14 13...
Backup Job 103                                                              Failed                                          Created by * at 2013-05-14 13...


\Masonit
masonit
Service Provider
 
Posts: 141
Liked: 10 times
Joined: Tue Oct 09, 2012 2:30 pm
Full Name: Magnus Andersson

Re: Unsuccesful jobs

Veeam Logoby v.Eremin » Tue May 14, 2013 12:47 pm

I can not run that script. I get "VeeamPSS is not installed on this computer".

I’ve corrected the typo already, so, please, try again.

As to the sessions, please be aware that if the job has finished with “Failed” status, it doesn’t necessarily mean that some VM has failed during last session. For instance, if the job was manually stopped at the very begging (even before it managed to process any Virtual Machine), it'd result in "Failed" job status, meanwhile, none of the VM literally failed, etc.

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

[MERGED] : list all VM for each job

Veeam Logoby EPSMAL » Wed May 15, 2013 2:16 pm

Hello everybody,

i have a problem with a script.
i would like to list for each job, the backup result for each VM.

Code: Select all
foreach($Job in (Get-VBRJob )) {
   $Session = $Job.FindLastSession()
   $Info = $Session.GetTaskSessions()
foreach ($VM in $info) {
echo $job.Name
echo $VM.Name
echo $VM.status
}
}


i have 2 jobs : LINUX and WINDOWS
when the status job is sucess : there are no problem, all VMs are listed
but for exemple, when a job has failed and when the job has retried , i have a few VMs because de lastjob is the job who has been retried

How can i list all vms ?
thanks for your help
best regards
EPSMAL
Lurker
 
Posts: 0
Liked: never
Joined: Tue Aug 07, 2012 6:37 am
Full Name: EPSMAL

Re: Unsuccesful jobs

Veeam Logoby v.Eremin » Wed May 15, 2013 3:56 pm

You’ve been merged to the existing discussion which is concerned with similar issue.

From my perspective, if you modify code provided above, you'll be able to meet your expectations:

Code: Select all
asnp VeeamPSSnapin
Function Failed([Veeam.Backup.Core.CBackupJob]$Job)
{
     $Job.FindLastSession().Gettasksessions() | ? {$_.Status -eq "Failed"}
}
Function Warning([Veeam.Backup.Core.CBackupJob]$Job)
{
  $Sessions = Get-VBRBackupSession -name $Job.name | ?{$_.CreationTime -ge (Get-Date).addhours(-$Interval)}
  foreach ($session in $Sessions)
  {
     $session.Gettasksessions() | ? {$_.Status -eq "Warning"}
  }
}
Function Successful([Veeam.Backup.Core.CBackupJob]$Job)
{
  $Sessions = Get-VBRBackupSession -name $Job.name | ?{$_.CreationTime -ge (Get-Date).addhours(-$Interval)}
  foreach ($session in $Sessions)
  {
     $session.Gettasksessions() | ? {$_.Status -eq "Success"}
  }
}
$Job = Get-VBRJob -name (read-host "Name of your Job")
$Interval = ([datetime]$Job.ScheduleOptions.NextRun).Subtract([datetime]$Job.ScheduleOptions.LatestRun).TotalHours
Get-VBRJob -name $Job.name | Select-Object -Property @{N="Name";E={$_.Name}} ,@{N="Last result";E={$_.GetLastResult()}}, @{N="Failed VM";E={(Failed $_).name}} ,@{N="VM with warning";E={(Warning $_).name}},@{N="Successful";E={(Successful $_).name}}| Sort Name -Descending | Format-Table

Firstly, you’ll be asked to input name of the corresponding job.

Secondly, the script will determine the interval throughout which it will try to find job sessions. The interval is defined as a time period between latest job run and the next one. In general, the interval is required in order to catch only those task sessions that are related to the latest job run.

Thirdly, the determined interval, as well as, the job name will be passed to custom functions (Failed, VM with warnings, Successful).

Fourthly, custom functions, using the passed interval, will find VM with corresponding status.

Fifthly, the script will create a table using the data provided by custom functions. As the result you will get something like this:

Code: Select all
Name of your Job: Vi-Test#50

Name                                           Last result Failed VM                    VM with warning              Successful                 
----                                           ----------- ---------                    ---------------              ----------                 
VI-Test#50                                          Failed VM#3                                                                         


To be honest, I haven’t had enough time/resources to test this script thoughtfully, thus, all comments/feedback are highly-appreciated.

Hope this helps.
Thanks.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Unsuccesful jobs

Veeam Logoby EPSMAL » Thu May 16, 2013 9:34 am

Hello, thanks for your answers.

I am going to test it.

Thanks

best regards
EPSMAL
Lurker
 
Posts: 0
Liked: never
Joined: Tue Aug 07, 2012 6:37 am
Full Name: EPSMAL

Re: Unsuccesful jobs

Veeam Logoby v.Eremin » Thu May 16, 2013 10:14 am

I’ve split your answer in order not to overfill the existing topic with irrelevant discussion.

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

Re: Unsuccesful jobs

Veeam Logoby masonit » Thu May 16, 2013 12:19 pm

v.Eremin wrote:
I can not run that script. I get "VeeamPSS is not installed on this computer".

I’ve corrected the typo already, so, please, try again.

As to the sessions, please be aware that if the job has finished with “Failed” status, it doesn’t necessarily mean that some VM has failed during last session. For instance, if the job was manually stopped at the very begging (even before it managed to process any Virtual Machine), it'd result in "Failed" job status, meanwhile, none of the VM literally failed, etc.

Thanks.


Hi v.Eremin, still can't run the script: Object reference not set to an instance of an object

But never mind. Today the script runs fine. I get VM name on all failed jobs! :)
I saw now that the failed job with the vm name that didn't show. That job was started manually and not as a scheduled job. Could that explain the issue?

\Masonit
masonit
Service Provider
 
Posts: 141
Liked: 10 times
Joined: Tue Oct 09, 2012 2:30 pm
Full Name: Magnus Andersson

Re: Unsuccesful jobs

Veeam Logoby v.Eremin » Mon May 20, 2013 10:29 am

Could that explain the issue?

No, I believe, it can’t be the issue, since all task sessions (be it manual job execution or automatic one) are tracked in the same manner.

Anyway, glad to hear that nowadays everything works as expected.

Should any other questions arise, don’t hesitate to contact me. Thanks.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Previous

Return to PowerShell



Who is online

Users browsing this forum: No registered users and 4 guests