PowerShell - Get-VbrJob

PowerShell script exchange

Re: PowerShell - Get-VbrJob

Veeam Logoby Sethbartlett » Wed Nov 23, 2011 7:19 pm

I have been trying to go over some of this, it looks like it may be something with your code that is flipping them the wrong way. If you notice, it is completely backwards. I notice you are doing

Code: Select all
 $JobStats = Get-JobStatistics $job.Name


Which is probably linking everything together as I would imagine(Doing get-vbrbackup, get-vbrsession and such) but is matching them backwards basically. Does this make sense?
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 ThomasMc » Wed Nov 23, 2011 7:22 pm

Is it just me or does the VBRBackupSessions not like sorting properly
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 Sethbartlett » Wed Nov 23, 2011 7:51 pm

I agree completely, it doesn't sort by anything from the looks of it >_<
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 ThomasMc » Wed Nov 23, 2011 7:56 pm

this should be enough to get you back on track

Code: Select all
$jobName = "JobName"

$job = Get-VBRJob | ?{$_.Name -eq $jobName}

$table = New-Object system.Data.DataTable "$table01"

$col1 = New-Object system.Data.DataColumn JobName,([string])
$col2 = New-Object system.Data.DataColumn StartTime,([DateTime])
$col3 = New-Object system.Data.DataColumn StopTime,([DateTime])

$table.columns.add($col1)
$table.columns.add($col2)
$table.columns.add($col3)


$session = Get-VBRBackupSession | ?{$_.JobId -eq $job.Id} | %{$row = $table.NewRow();$row.JobName = $_.Info.JobName;$row.StartTime = $_.Info.CreationTime;$row.StopTime = $_.Info.EndTime;$table.Rows.Add($row)}

$intrestingsesh = $table | Sort StartTime -descending | select -first 3

$backup = Get-VBRBackup | ?{$_.JobId -eq $job.Id}

$points = $backup.GetStorages() | sort CreationTime -descending | Select -First 3


$intrestingsesh

$points | Select FileName, CreationTime | ft


[edit]
cleaned it up
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 ThomasMc » Thu Nov 24, 2011 12:01 am

A better example

Code: Select all
$jobName = "JobName"

$job = Get-VBRJob | ?{$_.Name -eq $jobName}

$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])

$table.columns.add($col1)
$table.columns.add($col2)
$table.columns.add($col3)
$table.columns.add($col4)
$table.columns.add($col5)
$table.columns.add($col6)

$session = Get-VBRBackupSession | ?{$_.JobId -eq $job.Id} | %{$row = $table.NewRow();$row.JobName = $_.Info.JobName;$row.StartTime = $_.Info.CreationTime;$row.StopTime = $_.Info.EndTime;$table.Rows.Add($row)}

$intrestingsesh = $table | Sort StartTime -descending | select -first 3

$pkc = 1

$intrestingsesh | foreach {$_.Index = $pkc; $pkc+=1}

$backup = Get-VBRBackup | ?{$_.JobId -eq $job.Id}

$points = $backup.GetStorages() | sort CreationTime -descending | Select -First 3

$ic = 1
ForEach ($point in $points) {
   $rows = $table | ?{$_.Index -eq $ic}
   ForEach ($row in $rows) {
      ($row.FileName = $point.FileName) -and ($row.CreationTime = $point.CreationTime); $ic+=1
   }
}

$intrestingsesh
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 » Thu Nov 24, 2011 12:42 am

Nice one Thomas.

I just haven't had the time today/tonight to look at this again. I'll have to get to it tomorrow or the weekend :(

Anyway, here is where I got up to. Its generating the info I need, but as I said before, the sorting is not right. Maybe after I look at your examples you have posted above/previously I'll get some ideas to help fix my sorting.

My attempt so far:
Code: Select all
$SessionsToFetch = 3
$indexvalue = 0

Function Get-JobStatistics ($Backup) {

   $BackupArchive = Get-VBRBackup | ?{$_.JobName -eq $Backup}
   $BackupFiles = $BackupArchive.GetStorages() | sort CreationTime -descending | select -Index $indexvalue
   $BI = $BackupFiles.info
   $BS = $BackupFiles.stats
   [hashtable]$Return = @{}
   $Return.Name = $Backup
   $Return.FileName = $BackupFiles.FileName
   $Return.BackupSize = $BS.BackupSize / 1GB
   $Return.DedupRatio = $BS.DedupRatio
   $Return.CompressRatio = $BS.CompressRatio
   $Return.CreationTime = $BI.CreationTime.DateTime
   Return $Return

}

$Report = @()
$Jobs = Get-VBRJob
foreach ($job in $Jobs) {
   $indexvalue = 0
   $BackupSessions = Get-VBRBackupSession | ?{$_.JobId -eq $job.Id} | sort -Property CreationTime -Descending | Select -First $SessionsToFetch
   foreach ($session in $BackupSessions) {
      
      $row = "" | Select JobName, FullBackup, StartTime, EndTime, Duration, BackupSizeGB, DedupRatio, Compression, Result
      $JobStats = Get-JobStatistics $job.Name
      $indexvalue++ #only increment index value after jobstatistics have been fetched from function as index value of job creation should match backupsession value.
      $indexvalue
      $row.JobName = $job.Name
      $row.FullBackup = $session.Info.IsStartFullMode
      $row.StartTime = $session.Info.CreationTime
      $row.EndTime = $session.Info.EndTime
      $Duration = $session.Info.EndTime - $session.Info.CreationTime #When subtracting two Date-Time data types you are left with a [TimeSpan] data type.
      $TimeSpan = $Duration #TimeSpan here
      # you would have to get the desired TimeSpan values to the Format operator
      $Duration = '{0:00}:{1:00}:{2:00}' -f $TimeSpan.Hours, $TimeSpan.Minutes, $TimeSpan.Seconds
      $row.Duration = $Duration
      $row.BackupSizeGB = "{0:N3}" -f $JobStats.BackupSize
      $row.BackupSizeGB
      $row.DedupRatio = $JobStats.DedupRatio
      $row.Compression = $JobStats.CompressRatio
      $row.Result = $session.Info.Result
      
      $Report += $row
      }
   }
Write-Host "Report"
Write-Host "------"
$Report #display report in console
$Report | ConvertTo-Html | Out-File "C:\temp\Veeam_Report2.html" #write report to HTML
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 » Sat Nov 26, 2011 3:15 am

ThomasMc, I must thank you for your examples and help in this thread :) I have now completed my script with the info I needed via a combination of your code and my own. I have added a couple of fields too and some nice formatting features.

So to summarise, this script runs on your Veeam Backup server/environment, and gathers all the Backup session info for all your jobs (or you can change the -match parameter and search for jobs with certain names/phrases in them to!) It grabs a certain number of sessions you specify for each job, and feeds back all the interesting info to you - such as start time, end time, duration of job, average speed, what kind it was (incremental or full i.e. VBK or VIB), its success/failure etc...

For me, this is great, as I have been tasked with finding out how a large number of jobs are performing (time they complete in and average speeds) (there are 50+ Veeam B&R jobs in our environment)! I can now just run this one script, and gather all the info in one swoop. If anyone wants a modified copy that will email the report to you instead of saving it to c:\ (or would like both) just shout and I'll change it for you to include both.

Lastly, ThomasMc, would you mind if I added this script to my own personal blog? I will attribute help from you there of course :)

Veeam Backup Job / Session statistics and performance report
--------------------------------------------------------------------------
Tested on:
Veeam B&R 5.0.2.230

Requires:
-----------
PowerShell 2.0
Veeam PowerShell module that comes with Veeam B&R 5.0 +

Download here: http://dl.dropbox.com/u/450727/scripts/Veeam-Backup-Report.zip

Example of output - grabbing 3 last sessions for each job on my lab Veeam server (I let the first job fail those 3 times to show how the output changes):
Image
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 » Sat Nov 26, 2011 12:15 pm

Awesome work and I don't mind at all :)
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 ThomasMc » Sat Nov 26, 2011 5:15 pm

Last update I think lol heres an easy fix

Code: Select all
$VBRBackupSessions = Get-VBRBackupSession
$VBRBackupSessions | Add-Member -type NoteProperty -name StartTime -value ([System.DateTime])
$null = $VBRBackupSessions | %{$_.StartTime = $_.Info.CreationTime}

$VBRBackupSessions | ?{$_.Name -eq "JobName"} | Sort StartTime -Descending | Select -First 3

$ss = $VBRBackupSessions | ?{$_.Name -eq "JobName"} | Sort StartTime -Descending | Select -First 1
$ss | fl
$ss.Info
$ss.progress
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 mfrycz » Fri Jan 06, 2012 11:16 am

Script looks great guys,

I just have few questions:

1. I cannot dig deeper than Get-VBRBackupSession | Get-Member - membertype Property reason for more detail is that I will need to change some results
2. We have several Veeam servers and will need quote against them all
3. Could this be set up to report against particular name (ie. one job can have several vm's and not sure if we could report only on the job level or as grannular as vm level)

I am not very familiar with PS but so far i am amazed by what can it do...

Thanks for all your hard work guys
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 mfrycz » Fri Jan 06, 2012 1:59 pm

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.
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 ThomasMc » Sat Jan 07, 2012 8:14 pm

Not sure is Sean still pops by the forums but you can contact him on twitter(@shogan85) or via his website(Shogan.tech) bearing in mind that your asking for a fair bit of work being done to his original report but since hes a blogger you might just be in luck :D
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 » Mon Jan 09, 2012 9:25 am

Hey guys,

Thomas, thanks for the mention :)

Marcin, I'll take another look at your questions - possibly later on this week - I have a bunch of exams mid week and as a result have been studying just about flat out in my spare time. I caught the update on this thread in my Veeam Community Digest email this morning :) Regarding your query about looking at stats on other Veeam Backup Servers - I'm sure this can be done using PowerShell Remoting, unfortunately I have only worked a little bit with Remoting - but it should just be a case of connecting to the remote server and running the same cmdlets against it to retrieve data. Anyway, as I mentioned, I'll try look into your queries a bit later this week if I get a chance :)

Sean
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 » Mon Jan 09, 2012 10:18 am

Welcome back Sean :) and good luck with the exams.

@Seth I see we got a mention in community mailer :D
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 » Mon Jan 09, 2012 10:29 am

ThomasMc wrote:Welcome back Sean :) and good luck with the exams.

@Seth I see we got a mention in community mailer :D


Thanks Thomas :) Yes, well done to you guys! I was happy to see a dedicated PowerShell sub-forum pop up a number of weeks back.

PS I also have another useful reporting script to add here soon - as soon as I get a chance to post it up!
Shogan
Enthusiast
 
Posts: 56
Liked: never
Joined: Fri Dec 18, 2009 11:16 pm
Full Name: Sean Duffy

PreviousNext

Return to PowerShell



Who is online

Users browsing this forum: No registered users and 6 guests