PowerShell script exchange
Post Reply
Markol
Enthusiast
Posts: 26
Liked: 2 times
Joined: Apr 20, 2012 12:12 pm
Full Name: Marko Lehto
Contact:

Getting average from veeam backups

Post by Markol »

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
tsightler
VP, Product Management
Posts: 6035
Liked: 2860 times
Joined: Jun 05, 2009 12:57 pm
Full Name: Tom Sightler
Contact:

Re: Getting average from veeam backups

Post by tsightler »

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.
Markol
Enthusiast
Posts: 26
Liked: 2 times
Joined: Apr 20, 2012 12:12 pm
Full Name: Marko Lehto
Contact:

Re: Getting average from veeam backups

Post by Markol »

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
tsightler
VP, Product Management
Posts: 6035
Liked: 2860 times
Joined: Jun 05, 2009 12:57 pm
Full Name: Tom Sightler
Contact:

Re: Getting average from veeam backups

Post by tsightler »

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.
Markol
Enthusiast
Posts: 26
Liked: 2 times
Joined: Apr 20, 2012 12:12 pm
Full Name: Marko Lehto
Contact:

Re: Getting average from veeam backups

Post by Markol »

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.
veremin
Product Manager
Posts: 20415
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Getting average from veeam backups

Post by veremin »

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.
Markol
Enthusiast
Posts: 26
Liked: 2 times
Joined: Apr 20, 2012 12:12 pm
Full Name: Marko Lehto
Contact:

Re: Getting average from veeam backups

Post by Markol »

v.Eremin wrote: 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)
veremin
Product Manager
Posts: 20415
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Getting average from veeam backups

Post by veremin »

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.
Markol
Enthusiast
Posts: 26
Liked: 2 times
Joined: Apr 20, 2012 12:12 pm
Full Name: Marko Lehto
Contact:

Re: Getting average from veeam backups

Post by Markol »

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: Apr 20, 2012 12:12 pm
Full Name: Marko Lehto
Contact:

Re: Getting average from veeam backups

Post by Markol »

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
veremin
Product Manager
Posts: 20415
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Getting average from veeam backups

Post by veremin »

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.
Post Reply

Who is online

Users browsing this forum: No registered users and 10 guests