Getting average from veeam backups

PowerShell script exchange

Getting average from veeam backups

Veeam Logoby Markol » Wed Aug 20, 2014 12:29 pm

Hi all,

Found a pice of code that
tsightler
did.. And it's what I'm loking for but... abit more.. I need to include this into my old script, This is we did a change in the v-center and created folders where we put in all the vm's and in veeam the same thing take backup of that folder...
just to make things a bit simpler for us..

but then I can't use the old script that I have to get the average and so on from the backups, and the code from tsightler.. might do the trick, but I need the help to understand where to add it..

Here is his script part:

Code: Select all
$jobname = "weekly-production-noAAP"

   
    $vmsandtemplates = Find-VBRViEntity -VMsAndTemplates
    $vmfoldertree = $vmsandtemplates |? {$_.Type -eq "Vm"}
    $vmfolders = $vmsandtemplates |? {$_.Type -eq "Folder"}
   
   $job = Get-VBRJob -Name $jobname | Sort -Property Name
       
    $jobobjs = $job.GetObjectsInJob() | ?{$_.Type -eq "Include"}
   
    $jobobjid = $jobobjs.GetObject().Info.HostId.ToString() + "_" + $jobobjs.GetObject().Info.ObjectId
    $jobobjpath = ($vmfolders | ?{$_.Id -eq "$jobobjid"}).Path
    write-host $jobobjpath
   
    $vmsinfolder= $vmfoldertree |?{$_.Path -like "$jobobjpath*"} | Sort -Property Name

    ForEach ($vm in $vmsinfolder) {
        write-host "   " $vm.Name
    }


And the code that I have now..

Code: Select all
$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>
"@
Add-PSSnapin VeeamPSSnapIn


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


foreach ($job in $Jobs) {
    $jobName = $job.Name
    $table = New-Object system.Data.DataTable "$table01"
   
   
    $col1 = New-Object system.Data.DataColumn Index,([int])
    $col2 = New-Object system.Data.DataColumn JobName,([string])
    $col3 = New-Object system.Data.DataColumn StartTime,([DateTime])
    $col4 = New-Object system.Data.DataColumn StopTime,([DateTime])
    $col5 = New-Object system.Data.DataColumn FileName,([string])
    $col6 = New-Object system.Data.DataColumn CreationTime,([DateTime])
    $col7 = New-Object system.Data.DataColumn AvgSpeedMB,([int])
    $col8 = New-Object system.Data.DataColumn Duration,([TimeSpan])
    $col9 = 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)
       
    $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)
           
         $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 {
                   
               $row.Result = $_.Result
               }
            #Add this calculated row to the $table.Rows
         $table.Rows.Add($row)
        }

   
  # $interestingsess = $table | Sort StartTime -descending | select -first 4
   $interestingsess = $table | Where { ($_.StartTime) -gt (Get-Date 2014-08-10)} | Sort StartTime
 $interestingsess
 
 
    $pkc = 1
    #if ($interestingsess -ne $Null){
     #   Write-Output "KpyTo!"

    $interestingsess | foreach {
     
      $_.Index = $pkc
      #Increment $pkc, so the next foreach loop assigns a higher value to the next .Index property on the next row.
      $pkc+=1
   }
   
   
   $backup = Get-VBRBackup | ?{$_.JobId -eq $job.Id}
    #$points = $backup.GetStorages() | sort CreationTime -descending | Select -First 4
   $points = $backup.GetStorages() | sort CreationTime -descending | Where-Object {$_.CreationTime -gt "2014-08-10"}

   $ic = 1
    ForEach ($point in $points) {
             $rows = $table | ?{$_.Index -eq $ic}
       #inner ForEach loop to assign the value of the backup point's filename to the row's .FileName property as well as the creation time.
      ForEach ($row in $rows) {
          ($row.FileName = $point.FileName) -and ($row.CreationTime = $point.CreationTime)
        #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, 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:\Veeam-Backup.htm
Markol
Enthusiast
 
Posts: 26
Liked: 2 times
Joined: Fri Apr 20, 2012 12:12 pm
Full Name: Marko Lehto

Re: Getting average from veeam backups

Veeam Logoby tsightler » Wed Aug 20, 2014 1:04 pm

It's not clear to me why using folders has any impact on your original code. The original report only collects and reports on job level statistics and seems to work if a job is VM or folder based. There are some bugs in how it reports the filenames (perhaps only visible if using reverse incremental), but I was able to run it against jobs that use folders with no issues.

The code of mine that you found above is used to determine which VMs are within a folder. It's probably not required if you just want to report on per-VM backup session data as you can get that detail from the job runs themselves using the Get-VBRTaskSession. This cmdlet will give you job details for each individual VM processed by the job session.
tsightler
Veeam Software
 
Posts: 4769
Liked: 1737 times
Joined: Fri Jun 05, 2009 12:57 pm
Full Name: Tom Sightler

Re: Getting average from veeam backups

Veeam Logoby Markol » Wed Aug 20, 2014 1:57 pm

well yes I can run the script now as you say, but it then only show me the average for that job, not for the vm's that are located in that folder/job
Markol
Enthusiast
 
Posts: 26
Liked: 2 times
Joined: Fri Apr 20, 2012 12:12 pm
Full Name: Marko Lehto

Re: Getting average from veeam backups

Veeam Logoby tsightler » Wed Aug 20, 2014 3:35 pm

Right, but I don't see anything in the code above that would have done that anyway. I guess that's why I'm confused, the code your posted for your report was always just based on job. Are you perhaps saying that previously you had one job for each VM? As I noted above, you can use Get-VBRTaskSession cmdlet to get specific details for each VM within the job.
tsightler
Veeam Software
 
Posts: 4769
Liked: 1737 times
Joined: Fri Jun 05, 2009 12:57 pm
Full Name: Tom Sightler

Re: Getting average from veeam backups

Veeam Logoby Markol » Thu Aug 21, 2014 8:00 am

ok,but can Get-VBRTaskSession get me that info from let's say 1 of jan this year?
The thing is that I'm running this scrit once a month. to gather the repport to our customers. I'll try to take a look at this cmdlet.
Markol
Enthusiast
 
Posts: 26
Liked: 2 times
Joined: Fri Apr 20, 2012 12:12 pm
Full Name: Marko Lehto

Re: Getting average from veeam backups

Veeam Logoby v.Eremin » Thu Aug 21, 2014 12:39 pm

Markol wrote:ok,but can Get-VBRTaskSession get me that info from let's say 1 of jan this year?

The following script should be helpful:

Code: Select all
Asnp VeeamPSsnapin
$BackupSession = Get-VBRBackupSession | where {$_.Jobname -eq "Name of your backup job"}
$January = Get-Date -Month 1
$Januarysessions = $BackupSession | where {$_.creationtime.month -eq $January.Month}
$Januarysessions | Get-VBRTaskSession


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

Re: Getting average from veeam backups

Veeam Logoby Markol » Mon Aug 25, 2014 8:18 am

v.Eremin wrote:
Markol wrote:ok,but can Get-VBRTaskSession get me that info from let's say 1 of jan this year?

The following script should be helpful:

Code: Select all
Asnp VeeamPSsnapin
$BackupSession = Get-VBRBackupSession | where {$_.Jobname -eq "Name of your backup job"}
$January = Get-Date -Month 1
$Januarysessions = $BackupSession | where {$_.creationtime.month -eq $January.Month}
$Januarysessions | Get-VBRTaskSession


Thanks.


Thanks, what I menat and should wrote taht when we run the script it need to get all the jobas from 1jan untill this day.
Or does this just get me all the jobs from Jan? haven't tride this part yest(been sick all weekend)
Markol
Enthusiast
 
Posts: 26
Liked: 2 times
Joined: Fri Apr 20, 2012 12:12 pm
Full Name: Marko Lehto

Re: Getting average from veeam backups

Veeam Logoby v.Eremin » Mon Aug 25, 2014 8:52 am

The script returns sessions of specific job ("Name of your backup job") that occurred on a given month ("January"). Of course, it can be modified futher to return sessions of all jobs that took place on a specified month. Thanks.
v.Eremin
Veeam Software
 
Posts: 13285
Liked: 971 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Getting average from veeam backups

Veeam Logoby Markol » Mon Aug 25, 2014 1:59 pm

Tried the script now and, big thanks. But now the problem is for me to try to insert this part into the scipt that I had before
Markol
Enthusiast
 
Posts: 26
Liked: 2 times
Joined: Fri Apr 20, 2012 12:12 pm
Full Name: Marko Lehto

Re: Getting average from veeam backups

Veeam Logoby Markol » Wed Aug 27, 2014 11:21 am

Or as when you right-click the job and chose report you will see the jobs duration and all the vm's

name,status,start time,end time,size, read, transferred and duration.

And when i run the script I need it to get all of the jobs that has run from 1 of Jan until today
Markol
Enthusiast
 
Posts: 26
Liked: 2 times
Joined: Fri Apr 20, 2012 12:12 pm
Full Name: Marko Lehto

Re: Getting average from veeam backups

Veeam Logoby v.Eremin » Wed Aug 27, 2014 11:27 am

Then, in order to get job sessions that have occurred since January you need to modify only one line:

Code: Select all
$SessionsSinceJanuary = $BackupSession | where {$_.creationtime.month -ge $January.Month}
$SessionsSinceJanuary | Get-VBRTaskSession


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: Google [Bot] and 7 guests