List only last Full Backup

PowerShell script exchange

List only last Full Backup

Veeam Logoby dellock6 » Tue Mar 26, 2013 11:59 am

Hi all,
bacause of my poor powrshell skills, I'm stuck at creating a simple script. The code right now is:

Code: Select all
Get-VBRBackupSession | where {S._JobType -eq "Backup" -AND S._IsFullMode -eq "True" -AND S._IsCompleted -eq "True" -AND S._Result -ne "Failed"  | select JobName, EndTime | sort JobName, EndTime


The code is working as expected, the only problem is a job with multiple full backups ended successfully, return me multiple lines in the final table. How can I enhance the script to show me only the newer backup of each job?

Thanks.
Luca.
Luca Dell'Oca
EMEA Cloud Architect @ Veeam Software

@dellock6
http://www.virtualtothecore.com
vExpert 2011-2012-2013-2014-2015-2016
Veeam VMCE #1
dellock6
Veeam Software
 
Posts: 5047
Liked: 1330 times
Joined: Sun Jul 26, 2009 3:39 pm
Location: Varese, Italy
Full Name: Luca Dell'Oca

Re: List only last Full Backup

Veeam Logoby v.Eremin » Tue Mar 26, 2013 12:45 pm 1 person likes this post

In the way I see it, something like this should work fine:

Code: Select all
asnp VeeamPSSnapin
foreach($job in (Get-VBRJob | ? {$_.JobType -eq "Backup"}))
{
Get-VBRBackupSession | ?{$_.Jobname -eq $Job.name -and $_.JobType -eq "Backup" -AND $_.IsFullMode -eq "True" -eq "True" -AND $_.IsCompleted -eq "True" -AND $_.Result -ne "Failed"} | Sort-Object EndTime -Descending | Select-Object -First 1 | select JobName, EndTime
}

Hope this helps.
Thanks.
v.Eremin
Veeam Software
 
Posts: 13255
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: List only last Full Backup

Veeam Logoby dellock6 » Tue Mar 26, 2013 1:32 pm

Works beautifully, thanks Vladimir (also for the code snippet to be re-used in other situations).

Luca.
Luca Dell'Oca
EMEA Cloud Architect @ Veeam Software

@dellock6
http://www.virtualtothecore.com
vExpert 2011-2012-2013-2014-2015-2016
Veeam VMCE #1
dellock6
Veeam Software
 
Posts: 5047
Liked: 1330 times
Joined: Sun Jul 26, 2009 3:39 pm
Location: Varese, Italy
Full Name: Luca Dell'Oca

Re: List only last Full Backup

Veeam Logoby dellock6 » Tue Mar 26, 2013 1:58 pm

Just an add: this script only shows completed full backups at first pass, if for some reason the full is completed after a retry for example (even for only a subset of the VMs included in the job) the job itself would not be listed by the script.

Luca.
Luca Dell'Oca
EMEA Cloud Architect @ Veeam Software

@dellock6
http://www.virtualtothecore.com
vExpert 2011-2012-2013-2014-2015-2016
Veeam VMCE #1
dellock6
Veeam Software
 
Posts: 5047
Liked: 1330 times
Joined: Sun Jul 26, 2009 3:39 pm
Location: Varese, Italy
Full Name: Luca Dell'Oca

Re: List only last Full Backup

Veeam Logoby v.Eremin » Tue Mar 26, 2013 2:17 pm

What about using additional parameter for retried sessions:

Code: Select all
$_.isretrymode -eq $true

Hope this helps.
Thanks.
v.Eremin
Veeam Software
 
Posts: 13255
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: List only last Full Backup

Veeam Logoby dellock6 » Tue Mar 26, 2013 2:42 pm

Thinking about it right now :)
I tried to add this in the original script in different positions as a -OR condition, but it return me the same small list, or the last retry execution regardless is a full or a reverse incremental... Not sure where and how to best place this piece of code...

Luca.
Luca Dell'Oca
EMEA Cloud Architect @ Veeam Software

@dellock6
http://www.virtualtothecore.com
vExpert 2011-2012-2013-2014-2015-2016
Veeam VMCE #1
dellock6
Veeam Software
 
Posts: 5047
Liked: 1330 times
Joined: Sun Jul 26, 2009 3:39 pm
Location: Varese, Italy
Full Name: Luca Dell'Oca

Re: List only last Full Backup

Veeam Logoby v.Eremin » Wed Mar 27, 2013 9:00 am

Unfortunately, there are no retried jobs with successful full backup in my lab, thus, it’s a little hard to test.

However, you can try to implement something like this and see whether it works. This script should list all successful full backup sessions either the retry mode is $true or $false:

Code: Select all
asnp VeeamPSSnapin
foreach($job in (Get-VBRJob | ? {$_.JobType -eq "Backup"}))
{
Get-VBRBackupSession | ?{$_.Jobname -eq $Job.name -and $_.JobType -eq "Backup" -and $_.IsFullMode -eq "True" -eq "True" -and $_.IsCompleted -eq "True" -AND $_.Result -ne "Failed" -and ($_.isretrymode -eq $False -or $True)} | Sort-Object EndTime -Descending | Select-Object -First 1 | select JobName, EndTime

Hope this helps.
Thanks.
v.Eremin
Veeam Software
 
Posts: 13255
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: List only last Full Backup

Veeam Logoby dellock6 » Wed Mar 27, 2013 9:18 am

Uhm, seems the same list is coming out as in the previous version of the script.
Anyway, at this stage the script is ok, it's also a way to know if for some reason a backup job has NEVER been able to complete without error.

Luca.
Luca Dell'Oca
EMEA Cloud Architect @ Veeam Software

@dellock6
http://www.virtualtothecore.com
vExpert 2011-2012-2013-2014-2015-2016
Veeam VMCE #1
dellock6
Veeam Software
 
Posts: 5047
Liked: 1330 times
Joined: Sun Jul 26, 2009 3:39 pm
Location: Varese, Italy
Full Name: Luca Dell'Oca

Re: List only last Full Backup

Veeam Logoby v.Eremin » Wed Mar 27, 2013 10:25 am

I’ve already changed slightly script provided above, and may be the following example will work as supposed:

Code: Select all
asnp VeeamPSSnapin
foreach($job in (Get-VBRJob | ? {$_.JobType -eq "Backup"}))
{
Get-VBRBackupSession | ?{$_.Jobname -eq $Job.name -and $_.JobType -eq "Backup" -and $_.IsFullMode -eq "True" -eq "True" -and $_.IsCompleted -eq "True" -and $_.Result -ne "Failed" -and ($_.isretrymode -eq $False -or $_.isretrymode -eq $True)} | Sort-Object EndTime -Descending | Select-Object -First 1 | select JobName, EndTime
}   

If it doesn’t, I will ask you to confirm that there are indeed retried full backup sessions which have finished successfully in your environment.
It can be done by running modified version of the script:

Code: Select all
asnp VeeamPSSnapin
foreach($job in (Get-VBRJob | ? {$_.JobType -eq "Backup"}))
{
Get-VBRBackupSession | ?{$_.Jobname -eq $Job.name -and $_.JobType -eq "Backup" -and $_.IsFullMode -eq "True" -eq "True" -and $_.IsCompleted -eq "True" -AND $_.Result -ne "Failed" -and $_.isretrymode -eq $True)} | Sort-Object EndTime -Descending | Select-Object -First 1 | select JobName, EndTime
}

Hope this helps.
Thanks.
v.Eremin
Veeam Software
 
Posts: 13255
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: List only last Full Backup

Veeam Logoby dellock6 » Wed Mar 27, 2013 11:35 am

Ah, the second script returns no result, so it seems there are no retried full backups. Maybe this is the reason why changing the original script gives no difference in the results....
So I may say the last version of the script is good to be used...

Luca.
Luca Dell'Oca
EMEA Cloud Architect @ Veeam Software

@dellock6
http://www.virtualtothecore.com
vExpert 2011-2012-2013-2014-2015-2016
Veeam VMCE #1
dellock6
Veeam Software
 
Posts: 5047
Liked: 1330 times
Joined: Sun Jul 26, 2009 3:39 pm
Location: Varese, Italy
Full Name: Luca Dell'Oca

Re: List only last Full Backup

Veeam Logoby v.Eremin » Wed Mar 27, 2013 11:59 am

So, I may say the last version of the script is good to be used.

Yep, I believe so.

Should any other questions regarding it arise, don’t hesitate to let me know.

Hope this helps.
Thanks.
v.Eremin
Veeam Software
 
Posts: 13255
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin


Return to PowerShell



Who is online

Users browsing this forum: No registered users and 8 guests