PowerShell - Get-VbrJob

PowerShell script exchange

PowerShell - Get-VbrJob

Veeam Logoby Shogan » Tue Nov 22, 2011 11:45 am

Hi all,

I am looking into the possibility of writing a small report on backup sessions that have completed in Veeam B&R using PowerShell in my spare time. I saw the cmdlet Get-VbrJob has a property "LastBackupSession" which returns the times of the last backup session. My question is, is it possible to rather get a list of backup sessions for the last week for example instead of just the "LastBackupSession"?

This way I can start reporting on things like how long each job took for each day of the week and hopefully further expand on that...

Understood that this may not be a supported topic, but any useful info would help. Thanks!
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 » Tue Nov 22, 2011 12:00 pm

Check out Get-VBRBackupSession, just filter as per required


e.g.
Code: Select all
Get-VBRBackupSession | ?{$_.Name -eq "JobName"} | Sort Logger -descending | Select -First 20
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 » Tue Nov 22, 2011 12:10 pm

Forget using the Logger for sort as it won't work but if you drill in a little further into the .info you get better detail than the stupid logger anyhoo
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 » Tue Nov 22, 2011 12:16 pm

Great! Thank you ThomasMc, I'll have a bit more of a dig around through available cmdlets when I get some time to look at this. Just tried out the Get-VBRBackupSession as you suggested and that has exactly what I was after for a start.

I see what you mean by the logger. Info has just what I need though - I can work with the Start and End times there. :)
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 » Tue Nov 22, 2011 5:15 pm

Another question - I started looking at this on my lunch break, and made a bit of progress. Now what I am looking for is a way to retrieve the data processing rate of a past Backup session. Any ideas? Nothing I can see in Get-VBRBackupSession seems useful at the moment. Is there another cmdlet or way to get at this kind of info?
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 » Tue Nov 22, 2011 5:50 pm

I haven't been looking for that value due to it being a bit ambiguous but if you look at the code I posted over here

viewtopic.php?f=2&t=9390

That will get you your actual backup size thus giving you start, stop and size so you could calculate your real tf rate
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 » Tue Nov 22, 2011 6:39 pm

if your not sure about comparing dates and times have a look below as PS makes it nice and easy

Code: Select all
$a = "22/11/2011 18:02"
$b = "22/11/2011 18:08"
New-Timespan $a $b


and so get what your looking for its

Code: Select all
(New-Timespan $a $b).TotalSeconds
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 » Tue Nov 22, 2011 6:49 pm

Thanks for the follow up ThomasMc :) Yes, I had worked out that subtracting a datetime from a datetime gave me a timespan. What I have done is take the timespan value and format it as 00:00:00 as in hh:mm:ss so that part is working nicely :) Right now I am working on your function from the other thread and finding out how I can match up the current Backup file it is looking at, to the current job session I am iterating through. That way I will tabulate the report based on each job session name, along with all the info I need!

Getting there :)
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 » Tue Nov 22, 2011 7:02 pm

Awesome, sounds as if your nearly done, I would love to see your finished script :)
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 » Tue Nov 22, 2011 7:09 pm

I'll be sure to post as soon as its ready. Thanks for your help thus far :)
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 » Wed Nov 23, 2011 9:36 am

Hi ThomasMc,

I got quite close to finishing yesterday, but am struggling to get my script right to match the correct records up (I am using a combination of Get-VBRJob objects to match against a combination of Get-VBRJobSession objects to give me all the data I need). I am using a nested foreach loop.

So for example, I would like to report on the last 3 sessions of each job that exists. So I do this:

Code: Select all
$Report = @()
$SessionsToFetch = 3
$indexvalue = 0
$Jobs = Get-VBRJob
foreach ($job in $Jobs) {
   $indexvalue = 0
   $BackupSessions = Get-VBRBackupSession | ?{$_.Name -eq $job.Name} | sort -Property $_.Info.CreationTime -Descending | Select -First $SessionsToFetch
   foreach ($session in $BackupSessions) {
      
      $row = "" | Select JobName, FullBackup, StartTime, EndTime, Duration, BackupSize, 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.
      $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.BackupSize = "{0:N3}" -f $JobStats.BackupSize
      $row.DedupRatio = $JobStats.DedupRatio
      $row.Compression = $JobStats.CompressRatio
      $row.Result = $session.Info.Result
      
      $Report += $row
      }
   }


Any way thats not the whole lot, there is a modified version of your function in there that helps gather the data, I just am looking at finding a good way of getting: Job name, start time, end time, duration, backup file size, whether or not it was a full backup, dedup ratio, compression ratio and success/no success all for the same backup session.

The above works, almost. It gathers all this info, but sometimes the wrong job session run is matched against the wrong backup session time. For example I might have one that shows it is a full backup, but the size is clearly an incremental run. Then below that, I see the full backup run size for an incremental run. Any better way of achieving this?
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 Nov 23, 2011 12:33 pm

I see what you mean, I've been having a little dig about to try and find a relation, I can't figure it out but I did uncover that in the Get-VBRBackupSession if you drill into Info.Progress it gives you a real speed i.e

In the GUI my rate was 2GB / s

and in PS it shows

137085132 for average speed and a quick / 1MB reveals 130.73 MB /s
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 Nov 23, 2011 1:35 pm

Nice find Thomas! I'll definitely add that into the report. If we can't find a work around to relate the jobs with the job sessions, I'll see what else I can figure out today/tonight and hope to soon have my script up here.
Shogan
Enthusiast
 
Posts: 56
Liked: never
Joined: Fri Dec 18, 2009 11:16 pm
Full Name: Sean Duffy

Re: PowerShell - Get-VbrJob

Veeam Logoby Sethbartlett » Wed Nov 23, 2011 2:11 pm

Shogan, could you show me your example of the incremental/full backup size mismatch you are seeing?
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 » Wed Nov 23, 2011 2:52 pm

Sethbartlett wrote:Shogan, could you show me your example of the incremental/full backup size mismatch you are seeing?


Hi Seth,

Sure, here is the output. Note how for the job "Daily VM Backup" there is a true value for the one job session listed there for "FullBackup" - meaning it should be the full backup - i.e. the .VBK. However, filesize is shown as 0.009GB - which is actually the file size for one of the incremental backups listed two rows below that session - and that row lists the correct full backup size of 1.78GB, even though that session is the incremental run.

Here is the output: I'll show you a screenshot of the actual backups of this job so you can match up how it should be too.

Image

Screenshot of "Daily VM Backup" backup files and stats:

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

Next

Return to PowerShell



Who is online

Users browsing this forum: No registered users and 3 guests