List failed servers

PowerShell script exchange

List failed servers

Veeam Logoby EvoTom » Thu Feb 28, 2013 3:10 pm

We have 6 Veeam Jobs each containing about 10 or so servers. What I am trying to do eventually in PowerShell is create a script that will run once a day and delete oracle archive redo logs if the backup job for the server was successful. If it is unsuccessful I want it to send an e-mail or something like that.

Anyway I am failing at the first hurdle which is to get a list of servers who's backup have failed.

I can get a list of failed jobs by running:

Code: Select all
Get-VBRJob | ? {$_.GetLastResult() -eq "Failed"}


and I can get the servers in that job by piping that into Get-VBRJobObject

Code: Select all
Get-VBRJob | ? {$_.GetLastResult() -eq "Failed"} | Get-VBRJobObject


what I can't seem to do is list which server(s) in the group of 10 or so was the one(s) that failed. I dont see a method for Get-VBRJobObject that will tell me.

Any ideas?
EvoTom
Enthusiast
 
Posts: 25
Liked: never
Joined: Wed Jul 11, 2012 10:18 am

Re: List failed servers

Veeam Logoby v.Eremin » Thu Feb 28, 2013 3:27 pm

Something like this should answer your requirements:

Code: Select all
asnp VeeamPSSnapin
$Job = Get-VBRJob -name "Name of your job"
$Session = $Job.FindLastSession()
$Session.GetTaskSessionsByStatus("Failed")


This script will list all VMs which failed to be backed up during the last run of the given job.

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

Re: List failed servers

Veeam Logoby EvoTom » Thu Feb 28, 2013 3:45 pm

That's perfect. Thank you!

I will probably have some more questions as I move forward with creating this script.
EvoTom
Enthusiast
 
Posts: 25
Liked: never
Joined: Wed Jul 11, 2012 10:18 am

Re: List failed servers

Veeam Logoby v.Eremin » Thu Feb 28, 2013 3:48 pm

I will probably have some more questions as I move forward with creating this script.

Don’t hesitate to let us know, should any additional help be needed.

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

Re: List failed servers

Veeam Logoby EvoTom » Thu Feb 28, 2013 4:26 pm

Is there a way to do it so that I can include all Jobs and just get a list of failed servers?

I have tried

Code: Select all
$Job = Get-VBRJob
$Session = $Job.FindLastSession()
$Session.GetTaskSessionsByStatus("Failed")}


but when i get to the $Session = $Job.FindLastSession() is throws an error.

Is there a way just to list the failed servers?
EvoTom
Enthusiast
 
Posts: 25
Liked: never
Joined: Wed Jul 11, 2012 10:18 am

Re: List failed servers

Veeam Logoby v.Eremin » Thu Feb 28, 2013 5:15 pm

Is there a way to do it so that I can include all Jobs and just get a list of failed servers?

Yep, I believe so.

Nevertheless, for doing it some sort of cycle should be implemented.

Code: Select all
asnp VeeamPSSnapin
foreach ($Job in Get-VBRJob | ? {$_.JobType -eq "Backup" -and $_.GetLastResult() -eq "Failed"})
{
    foreach ($failedVM in $Job.FindLastSession().GetTaskSessionsByStatus("Failed"))
    {
       write-host $failedVM.Name
    }
}


Please be aware that It’s nothing but a rough example; feel free to modify it however you want.

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

Re: List failed servers

Veeam Logoby EvoTom » Fri Mar 01, 2013 12:31 pm

This is a mostly a learning exercise (new to PowerShell) for me and I really appreciate the help. Just have one more question. I am now trying to get an e-mail sent for each failed VM. I get e-mail fine but the $srv.Name is not being passed to the -Body argument properly.

Here's the code:

Code: Select all
### Return servers which have failed.
$fails=foreach ($Job in Get-VBRJob | ? {$_.JobType -eq "Backup" -and $_.GetLastResult() -eq "Failed"})
   {
      foreach ($failedVM in $Job.FindLastSession().GetTaskSessionsByStatus("Failed"))
      {
         write-output $failedVM
      }
   }

### Mail settings
$MailSrv = "mailserver.company.com"
$MailFrom = "veeam@company.com"
$MailTo = "me@company.com"
$MailSbjt = "Veeam Job Failure Report"

### Send a mail for each failed server.
foreach ($srv in $fails)
   {
      $srv.Name
      Send-MailMessage -SmtpServer $MailSrv  -From $MailFrom -To $MailTo -Subject $MailSbjt -Body "$srv.Name failed"
   }


$srv.Name prints the server names to the screen fine. It's just that the e-mail body looks like this:

Veeam.Backup.Core.CBackupTaskSession.Name failed


Not really sure why...

Thanks again for the help.
EvoTom
Enthusiast
 
Posts: 25
Liked: never
Joined: Wed Jul 11, 2012 10:18 am

Re: List failed servers

Veeam Logoby EvoTom » Fri Mar 01, 2013 12:36 pm

Don't worry. I have figured it out. I don't think the -Body argument liked having a variable property so I just created a new variable to hold it. Send message bit looks like this now:

Code: Select all
foreach ($srv in $fails)
   {
      $body=$srv.Name
      Send-MailMessage -SmtpServer $MailSrv  -From $MailFrom -To $MailTo -Subject $MailSbjt -Body "$body failed"
   }
EvoTom
Enthusiast
 
Posts: 25
Liked: never
Joined: Wed Jul 11, 2012 10:18 am

Re: List failed servers

Veeam Logoby EvoTom » Fri Mar 01, 2013 12:52 pm

Think I actually getting somewhere now with this :D

Okay, I have a job with 5 servers in. One of the servers in the job fails causing the .GetLastResult of Get-VBRJob to equal "Failed". How do I list the servers in that Job that completed successfully.

Going back to earlier I tried this:

Code: Select all
asnp VeeamPSSnapin
$Job = Get-VBRJob -name "Name of your job"
$Session = $Job.FindLastSession()
$Session.GetTaskSessionsByStatus("Success")


I should find one server as we have a Job where one server has failed and the other one is successful. I also tried with the loop but again got no results:

Code: Select all
foreach ($Job in Get-VBRJob | ? {$_.JobType -eq "Backup" -and $_.GetLastResult() -eq "Failed"})
{
    foreach ($failedVM in $Job.FindLastSession().GetTaskSessionsByStatus("Success"))
    {
       write-host $failedVM.Name
    }
}


Any ideas on this one?
EvoTom
Enthusiast
 
Posts: 25
Liked: never
Joined: Wed Jul 11, 2012 10:18 am

Re: List failed servers

Veeam Logoby v.Eremin » Fri Mar 01, 2013 1:20 pm

I’ve just reproduced same situation in my test environment and the following script seems to work properly:

Code: Select all
Add-PSSnapin VeeamPSSnapin
foreach ($Job in Get-VBRJob | ? {$_.JobType -eq "Backup" -and $_.GetLastResult() -eq "Failed"})
{
    foreach ($failedVM in $Job.FindLastSession().GetTaskSessionsByStatus("Success"))
    {
       write-host $failedVM.Name
    }
}


So, if i were you, I’d doublecheck whether the given job failed during the last session and whether the VM you're talking about was backed up successfully during this session.

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

Re: List failed servers

Veeam Logoby EvoTom » Fri Mar 01, 2013 1:34 pm

Ah Ok. I think I have seen why it's not working for me. The first time the job runs the two servers run, one fails the other is successful. Then the job retries the failed server 3 times. This means that the last session for that job only the failed server runs (and fails).

Any ideas of getting round this?
EvoTom
Enthusiast
 
Posts: 25
Liked: never
Joined: Wed Jul 11, 2012 10:18 am

Re: List failed servers

Veeam Logoby v.Eremin » Fri Mar 01, 2013 2:52 pm

Hmm. May be something like this:

Code: Select all
asnp VeeamPSSnapin
$vbrsessions = Get-VBRBackupSession | ?{$_.JobType -eq "Backup" -and $_.EndTime -ge (Get-Date).adddays(-1) -and $_.result -eq "Failed"}
foreach ($session in $vbrsessions)
{
    foreach ($failedVM in $session.GetTaskSessionsByStatus("Success"))
    {
       write-host $failedVM.Name
    }

This script takes all backup sessions that have failed during the day and lists VMs that have been backed up successfully within them. However, under certain circumstances there might be a sight effect that some VM will be listed several times.

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

Re: List failed servers

Veeam Logoby aaronmnzs » Tue Feb 10, 2015 12:22 pm

is there a way wherein I could also list the error (Reason of failure) along with the failed VMs
aaronmnzs
Lurker
 
Posts: 1
Liked: never
Joined: Tue Feb 10, 2015 12:17 pm
Full Name: Aaron Menezes

Re: List failed servers

Veeam Logoby v.Eremin » Wed Feb 11, 2015 11:32 am

Try the following script and see whether it's something you're looking for:

Code: Select all
$vbrsessions = Get-VBRBackupSession | ?{$_.JobType -eq "Backup" -and $_.EndTime -ge (Get-Date).adddays(-1) -and $_.result -eq "Failed"}
foreach ($session in $vbrsessions)
{
    foreach ($failedVM in $session.GetTaskSessionsByStatus("Failed"))
    {
       write-host $failedVM.Name, $FailedVM.info.reason
    }


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

Re: List failed servers

Veeam Logoby baum1 » Tue Jun 09, 2015 1:23 pm

Hi, sorry for picking up this old thread!

We're using B&R 8 with latest SP and Windows 2012 Standard Server.

What I'm trying is to get a list of all failed VMs with the Veeam PSSnapin, we solved it so far that we'll getting a list of all failed VMs but with lots of information. We only need the Names of the failed ones. Is that possible with power shell? We're not very familiar with power shell..

Cheers
baum1
Lurker
 
Posts: 1
Liked: never
Joined: Tue Jun 09, 2015 1:16 pm
Location: Karlsruhe, Germany
Full Name: Christian Baumann

Next

Return to PowerShell



Who is online

Users browsing this forum: No registered users and 5 guests