PowerShell - Get-VbrJob

PowerShell script exchange

Re: PowerShell - Get-VbrJob

Veeam Logoby Sethbartlett » Mon Jan 09, 2012 1:40 pm

I was also happy to see a dedicated powershell forum. I use to search for the word "powershell" daily :P
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 - Get-VbrJob

Veeam Logoby Shogan » Mon Jan 09, 2012 1:56 pm

Sethbartlett wrote:I was also happy to see a dedicated powershell forum. I use to search for the word "powershell" daily :P


<-- PowerShell addict! :P Can't say I blame you though - I really enjoy writing scripts and learning with PS.
Shogan
Enthusiast
 
Posts: 56
Liked: never
Joined: Fri Dec 18, 2009 11:16 pm
Full Name: Sean Duffy

Re: PowerShell - Get-VbrJob

Veeam Logoby mfrycz » Tue Jan 10, 2012 9:23 am

Thanks a lot Shogan :)

hope this wont be much of a trouble to make this adjustments...

Also i am looking at this script myself (and if i will figure out something i definitelly post all discoveries)
mfrycz
Novice
 
Posts: 4
Liked: never
Joined: Wed Nov 23, 2011 4:05 pm
Location: London, UK
Full Name: Marcin Frycz

Re: PowerShell - Get-VbrJob

Veeam Logoby Shogan » Tue Jan 17, 2012 10:19 pm

mfrycz wrote:Hi guys,

this is really good piece of code :)

i am new to ps and trying to amend it slightly:

1. can it report insted of per-job details from per-vm details ?
2. can it specify just particular "*name*" or it have to be across all backups
3. i have several veeam servers, can i quote all of them ?
4. can we add size of the backup ?

thanks again for all your help.


Hi Marcin,

So I passed my VCP5 exam the other day, meaning I finally have a bit of time to catch up on other things going on outside of work! Anyway, I decided to have a quick look at your questions, and think I can answer some of them...

1. can it report instead of per-job details, per-VM details?

Well, I didn't have too much time to look into this, but I have a quick way to get the list of VMs in each Backup Job. Use the following:

Code: Select all
$Backups = Get-VBRBackup
foreach ($Backup in $Backups) {
   $Backup.Name
   Write-Host "--------------------------"
   $Backup.GetObjects() | Select Name
   Write-Host "--------------------------"
   }


There may be an even easier way, but that is how I figured that out. To get the actual per-VM details of each backup session - that I am not sure of. I had a quick look through the available cmdlets but did not see anything obvious. Perhaps someone else could identify a way of retrieving this info?

2. can it specify just particular "*name*" or it have to be across all backups

Yes - this is easy to change in the script - just change the line near the top of the script that reads:

Code: Select all
$Jobs = Get-VBRJob | ?{$_.Name -match ""}


to

Code: Select all
$Jobs = Get-VBRJob | ?{$_.Name -match "yourbackupname"}


the backup name you search for can be just a part of the name if you like - for example you could use "production" and all job names with the word "production" in it will be returned.

3. As I mentioned before, remoting may be a way of doing this - I currently don't have more than one Veeam server to test with, nor the time unfortunately - have a read up on PowerShell remoting / WinRM and perhaps you can find a way to modify the script to do this? Otherwise, my only other suggestion would be to run the script on each server and combine results.

4. Yes, I'm sure this is possible. In the Veeam v6 cmdlets, Get-VBRBackupSession returns all Backup Sessions and part of the info you can get out of each object returned is DataSize - which should be what you are looking for. I'll try this out in my script tomorrow and see if I can add a column for this, otherwise feel free to try yourself. Currently I have upgraded to v6 in my home lab and this script is for v5 so I can't test the v5 version with "DataSize" for you now. I'll have to wait till tomorrow when I am back at work / on lunch. But for v6 at home, I have confirmed this property is available.

e.g.

Code: Select all
$sessions = Get-VBRBackupSession
foreach ($sess in $sessions) { $sess.BackupStats }


This will show you all the stats you can get for each backup session object - one of these is the "DataSize"

Anyway, I'll try see what else I can do for your 4th query on DataSize and the script tomorrow. Hope that helps :)

For all others - this script doesn't work in Veeam B&R v6 in its current state (only for v5.x), however, I have updated it to work for v6 - well I have made another "V6" version - I'll upload it and post a link at some point tomorrow!
Shogan
Enthusiast
 
Posts: 56
Liked: never
Joined: Fri Dec 18, 2009 11:16 pm
Full Name: Sean Duffy

Re: PowerShell - Get-VbrJob

Veeam Logoby ThomasMc » Wed Jan 18, 2012 1:05 pm

On v6 there where some changes for the better to get this info :)

Code: Select all
[vPowerCLI] C:\>  $sess = (Get-VBRBackupSession | Sort CreationTime -Descending)[0]
[vPowerCLI] C:\>  $sess.BackupStats

            BackupSize               DataSize            DedupRatio         CompressRatio
            ----------               --------            ----------         -------------
             700036096             1583142727                   100                    44

[vPowerCLI] C:\>  $sess.GetTaskSessions()[0]
[vPowerCLI] C:\>  $sess.GetTaskSessions()[0].progress

TotalObjects      : 5
ProcessedObjects  : 5
TotalSize         : 147035105280
ProcessedSize     : 147035105280
ProcessedUsedSize : 74007285430
Progress          : 0
StartTime         : 18/01/2012 12:05:09
StopTime          : 18/01/2012 12:06:37
AvgSpeed          : 842022280
ReadSize          : 562036736
StoredSize        : 132517347
Bottleneck        : NotDefined
SourceStorage     : 0
SourceProxy       : 0
SourceNetwork     : 0
TargetStorage     : 0
TargetProxy       : 0
TargetNetwork     : 0
Duration          : 00:01:27.8940000
DisplayName       : 100% completed
_sourceStorage    : 0
_sourceProxy      : 0
_sourceNetwork    : 0
_targetStorage    : 0
_targetProxy      : 0
_targetNetwork    : 0
ThomasMc
Expert
 
Posts: 293
Liked: 17 times
Joined: Wed Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell

Re: PowerShell - Get-VbrJob

Veeam Logoby Shogan » Wed Jan 18, 2012 1:34 pm

ThomasMc wrote:On v6 there where some changes for the better to get this info :)

Code: Select all
[vPowerCLI] C:\>  $sess = (Get-VBRBackupSession | Sort CreationTime -Descending)[0]
[vPowerCLI] C:\>  $sess.BackupStats

            BackupSize               DataSize            DedupRatio         CompressRatio
            ----------               --------            ----------         -------------
             700036096             1583142727                   100                    44

[vPowerCLI] C:\>  $sess.GetTaskSessions()[0]
[vPowerCLI] C:\>  $sess.GetTaskSessions()[0].progress

TotalObjects      : 5
ProcessedObjects  : 5
TotalSize         : 147035105280
ProcessedSize     : 147035105280
ProcessedUsedSize : 74007285430
Progress          : 0
StartTime         : 18/01/2012 12:05:09
StopTime          : 18/01/2012 12:06:37
AvgSpeed          : 842022280
ReadSize          : 562036736
StoredSize        : 132517347
Bottleneck        : NotDefined
SourceStorage     : 0
SourceProxy       : 0
SourceNetwork     : 0
TargetStorage     : 0
TargetProxy       : 0
TargetNetwork     : 0
Duration          : 00:01:27.8940000
DisplayName       : 100% completed
_sourceStorage    : 0
_sourceProxy      : 0
_sourceNetwork    : 0
_targetStorage    : 0
_targetProxy      : 0
_targetNetwork    : 0


Thanks Thomas - I noticed the BackupStats seems new - couldn't find that in an install of v5 I have.

Also, Marcin, for you - see above in Thomas' post, I think this is the property would be looking for in answer to one of your questions:

StoredSize : 132517347
Shogan
Enthusiast
 
Posts: 56
Liked: never
Joined: Fri Dec 18, 2009 11:16 pm
Full Name: Sean Duffy

Re: PowerShell - Get-VbrJob

Veeam Logoby Shogan » Mon Jan 23, 2012 11:29 pm

v6 of the reporting script is up for those of you running Veeam B&R v6 - I have placed a download link on my original blog post - http://www.shogan.co.uk/?p=871

The only difference is that v6 PowerShell now returns information about the backup sessions in properties for each backup session object, not nested in the .Info. section. So instead of $_.Info.CreationTime, it would just be $_.CreationTime now for example :)
Shogan
Enthusiast
 
Posts: 56
Liked: never
Joined: Fri Dec 18, 2009 11:16 pm
Full Name: Sean Duffy

Re: PowerShell - Get-VbrJob

Veeam Logoby Andreas Neufert » Tue Jan 24, 2012 4:04 pm

Hello :-)

Shogan thanks for this outstanding script.

I extended your code because of a customer request in 2 ways:

1. Load VeeamPSSnapin
2. Add VMList to the table This is based on Shogans idea from his post 17 Jan 2012, 23:19

But be carefull the VMlist only reference to the actual include list of the job. So if you add or delete VMs in Jobs every table entry from the job changes.
Does anyone knows how to fix that.

Code: Select all
#load Veeam Powershell Snapin
Add-PSSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue
#Style
$style = @"
<style>
TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}
TH{border-width: 1px;padding: 2px;border-style: solid;border-color: black;background-color:orange}
TD{border-width: 1px;padding: 2px;border-style: solid;border-color: black;background-color:lightblue}
tr.special {background: #000080;} <tr class="special"></tr>
</style>
"@

$Report = @()
$Jobs = Get-VBRJob | ?{$_.Name -match ""}

foreach ($job in $Jobs) {
    $jobName = $job.Name
    $table = New-Object system.Data.DataTable "$table01"
   
   #region Setup table columns
    $col1 = New-Object system.Data.DataColumn Index,([int])
    $col2 = New-Object system.Data.DataColumn JobName,([string])
    $col3 = New-Object system.Data.DataColumn VMList,([String])
    $col4 = New-Object system.Data.DataColumn StartTime,([DateTime])
    $col5 = New-Object system.Data.DataColumn StopTime,([DateTime])
    $col6 = New-Object system.Data.DataColumn FileName,([string])
    $col7 = New-Object system.Data.DataColumn CreationTime,([DateTime])
    $col8 = New-Object system.Data.DataColumn AvgSpeedMB,([int])
    $col9 = New-Object system.Data.DataColumn Duration,([TimeSpan])
    $col10 = New-Object system.Data.DataColumn Result,([String])


    $table.columns.add($col1)
    $table.columns.add($col2)
    $table.columns.add($col3)
    $table.columns.add($col4)
    $table.columns.add($col5)
    $table.columns.add($col6)
    $table.columns.add($col7)
    $table.columns.add($col8)
    $table.columns.add($col9)
    $table.columns.add($col10)
   #endregion

   #Grab all Backup Sessions on the server where their .JobId property is the same as the Get-VBRJob objects .Id property
    $session = Get-VBRBackupSession | ?{$_.JobId -eq $job.Id} | %{
            $row = $table.NewRow()
            $row.JobName = $_.JobName
            $row.StartTime = $_.CreationTime
            $row.StopTime = $_.EndTime
            #Work out average speed in MB and round this to 0 decimal places, just like the Veeam GUI does.
         $row.AvgSpeedMB = [Math]::Round($_.Progress.AvgSpeed/1024/1024,0)
            #Duration is a Timespan value, so I am formatting in here using 3 properties - HH,MM,SS
         $row.Duration = '{0:00}:{1:00}:{2:00}' -f $_.Progress.Duration.Hours, $_.Progress.Duration.Minutes, $_.Progress.Duration.Seconds
           
            if ($_.Result -eq "Failed") {
                    #This is highlight is going to later be searched and replaced with HTML code to highlight failed jobs in RED :)
               $row.Result = "#HIGHLIGHTRED"+$_.Result+"HIGHLIGHTRED#"
                } else {
                    #Don't highlight if the backup session didn't fail.
               $row.Result = $_.Result
               }
            #Add this calculated row to the $table.Rows
         $table.Rows.Add($row)
        }

    $interestingsess = $table | Sort StartTime -descending | select -first 7
    $pkc = 1
    $interestingsess | foreach {
      #for every object in $interestingsess (which has now been sorted by StartTime) assign the current value of $pkc to the .Index property. 1,2,3,4,5,6 etc...
      $_.Index = $pkc
      #Increment $pkc, so the next foreach loop assigns a higher value to the next .Index property on the next row.
      $pkc+=1
   }

               
   #Now we are grabbing all the backup objects (same as viewing Backups in the Veeam B&R GUI Console
   $backup = Get-VBRBackup | ?{$_.JobId -eq $job.Id}
 
    $points = $backup.GetStorages() | sort CreationTime -descending | Select -First 7 #Find and assign the Veeam Backup files for each job we are going through and sort them in descending order. Select the specified amount.
    #Increment variable is set to 1 to start off
   $ic = 1
    ForEach ($point in $points) {
       #Match the $ic (Increment variable) up with the Index number we kept earlier, and assign $table to $rows where they are the same. This happens for each object in $points
      $rows = $table | ?{$_.Index -eq $ic}
                   
               
                   
                   
       #inner ForEach loop to assign the value of the backup point's filename and VMs to the row's .FileName property as well as the creation time.
      ForEach ($row in $rows) {
                $Backups = Get-VBRBackup  | ?{$_.JobId -eq $job.Id}
                $vms =
                foreach ($Backup in $Backups) {
                $Backup.GetObjects() | Select Name   
                }
                $vms1 =  $vms | out-string
                $vms1 = $vms1.replace("  " , "")
                $vms1 = $vms1.replace("Name" , "")
                $vms1 = $vms1.replace("----" , "")
                $vms1 = $vms1.replace("`r" , "")
                $vms1 = $vms1.replace("`n" , ";")
                $vms1 = $vms1.replace(";;;" , "")
                $vms1 = $vms1.replace("; ; ;" , "")
                $vms1 = $vms1.replace(" ;" , "; ")
          ($row.FileName = $point.FileName) -and ($row.CreationTime = $point.CreationTime) -and ($row.VMList = $vms1)
         

                     #Increment the $ic variable ( +1 )
        $ic+=1
          }
         
                         
    }
   #Tally up the current results into our $Report Array (add them)
    $Report += $interestingsess
}


#Now we select those values of interest to us and convert the lot into HTML, assigning the styling we defined at the beginning of this script too.
$Report = $Report | Select Index, JobName, VMList, StartTime, StopTime, FileName, CreationTime, AvgSpeedMB, Duration, Result| ConvertTo-HTML -head $style

#Interesting bit - replace the highlighted parts with HTML code to flag up Failed jobs.
$Report = $Report -replace "#HIGHLIGHTRED","<font color='red'><B>"
$Report = $Report -replace "HIGHLIGHTRED#","</font></B>"
#Finally, save the report to a file on your drive.
$Report | Set-Content C:\VBRpowershell\Veeam-Backup-Report.htm

Andreas Neufert
Veeam Software
 
Posts: 2201
Liked: 360 times
Joined: Wed May 04, 2011 8:36 am
Location: Germany
Full Name: @AndyandtheVMs Veeam PM

Re: PowerShell - Get-VbrJob

Veeam Logoby mfrycz » Wed Jan 25, 2012 11:15 am

@Shogan - Congrats on VCP5 (I had my exam in December)

@Andreas Neufert - I think your code is missing some things:
Code: Select all
ForEach ($row in $rows) {
                    $Backups = Get-VBRBackup  | ?{$_.JobId -eq $job.Id}
                    $vms =
                    foreach ($Backup in $Backups) {
                    $Backup.GetObjects() | Select Name   
                    }
                    $vms1 =  $vms | out-string
                    $vms1 = $vms1.replace("  " , "")
                    $vms1 = $vms1.replace("Name" , "")
                    $vms1 = $vms1.replace("----" , "")
                    $vms1 = $vms1.replace("`r" , "")
                    $vms1 = $vms1.replace("`n" , ";")
                    $vms1 = $vms1.replace(";;;" , "")
                    $vms1 = $vms1.replace("; ; ;" , "")
                    $vms1 = $vms1.replace(" ;" , "; ")
              ($row.FileName = $point.FileName) -and ($row.CreationTime = $point.CreationTime) -and ($row.VMList = $vms1)
             

                         #Increment the $ic variable ( +1 )
            $ic+=1
              }


$vms =
$Backup.GetObjects() | Select Name

I might be wrong but i am getting some errors while trying to execute it.

Although i have tried to reference StoredSize from preferences it still not working for me:

Code: Select all
 $session = Get-VBRBackupSession | ?{$_.JobId -eq $job.Id} | %{
            $row = $table.NewRow()
            $row.JobName = $_.Info.JobName
            $row.StartTime = $_.Info.CreationTime
            $row.StopTime = $_.Info.EndTime
       $row.StoredSize = $_.Info.Progress.StoredSize
            #Work out average speed in MB and round this to 0 decimal places, just like the Veeam GUI does.
       $row.AvgSpeedMB = [Math]::Round($_.Info.Progress.AvgSpeed/1024/1024,0)
            #Duration is a Timespan value, so I am formatting in here using 3 properties - HH,MM,SS
       $row.Duration = '{0:00}:{1:00}:{2:00}' -f $_.Info.Progress.Duration.Hours, $_.Info.Progress.Duration.Minutes, $_.Info.Progress.Duration.Seconds
           
            if ($_.Info.Result -eq "Failed") {
                    #This is highlight is going to later be searched and replaced with HTML code to highlight failed jobs in RED :)
               $row.Result = "#HIGHLIGHTRED"+$_.Info.Result+"HIGHLIGHTRED#"
                } else {
                    #Don't highlight if the backup session didn't fail.
               $row.Result = $_.Info.Result
               }
            #Add this calculated row to the $table.Rows
         
         $table.Rows.Add($row)
        }


$row.StoredSize = $_.Info.Progress.StoredSize

Any Ideas ?
mfrycz
Novice
 
Posts: 4
Liked: never
Joined: Wed Nov 23, 2011 4:05 pm
Location: London, UK
Full Name: Marcin Frycz

Re: PowerShell - Get-VbrJob

Veeam Logoby Andreas Neufert » Wed Jan 25, 2012 12:47 pm

Hi mfrycz,

I checked my code again.
Evenrything works without an error and the debuger in the powershell editor didn´t complain anything.

Can you please open the code in the powershell editor and execute it there. Please post the error here. THX.

CU Andy
Andreas Neufert
Veeam Software
 
Posts: 2201
Liked: 360 times
Joined: Wed May 04, 2011 8:36 am
Location: Germany
Full Name: @AndyandtheVMs Veeam PM

Re: PowerShell - Get-VbrJob

Veeam Logoby ThomasMc » Wed Jan 25, 2012 2:21 pm

Just for clarity

Datasize = Size of the whole backup file
StoreSize = Size of the VM inside the backup file

you can grab the Datasize very easily but if you want each VM StoreSize then you would have to loop the GetTaskSession() output
ThomasMc
Expert
 
Posts: 293
Liked: 17 times
Joined: Wed Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell

Previous

Return to PowerShell



Who is online

Users browsing this forum: No registered users and 3 guests