vRanger Automated Savepoint Cleanup

In our environment, we have configured vRanger to backup with the equivalent of 2 full backups and 6 incrementals before the earliest backup is overwritten.  This provides some protection against a single full backup becoming corrupted for whatever reason and rendering the entire backup of that virtual machine useless.  However, this configuration does add a significant complication.  Because vRanger requires that a backup be written successfully before purging the oldest one, this means that we requires 3x the space on our backup repository as is used in the production environment.  As most of our VMs are in the 50 to 100GB range, this is acceptable.  However, we have 4 VMs that are at or over 1TB in in size.  This means that we require 4TB * 3 copies = 12TB of disk space on our repository just for these VMs!  This doesn’t even include the incrementals either.  We simply do not have enough space on our backup repository at this time to support this along with all of our other VMs so a compromise was required.

vRanger jobs unfortunately do not allow for any kind of granularity in VM backup configuration so we are unable to adjust for these VMs there.  We could create separate jobs for these VMs but that introduces complications of its own.  The ultimately solution that I worked out as to write a Powershell script to run as a scheduled task each day that automatically deletes the oldest full backup for these VMs provided at least 2 exist.  It seems to work fairly well so I figured I’d include it here should it be useful to anyone else.

 

A few things to be aware of with this script:

–          The script only deletes oldest savepoint at the time of execution so if there are 3 fulls for example, only the oldest one is deleted
–          This can occur as if a VM changes more than 50% since the last full, as in this case a new full is performed which can result in multiple fulls for a single week
–          In this situation, the additional full will be deleted on the next execution of the script which will be the next day
–          The vRanger Powershell addin doesn’t support  the native 64 bit Powershell exe.  Therefore, to get it to work, you must run the x86 version in the scheduled task using the path:           

%SystemRoot%\syswow64\WindowsPowerShell\v1.0\powershell.exe

### ADD THE VRANGER POWERSHELL SNAPIN IF IT IS NOT ALREADY LOADED ###
if (-not (Get-PSSnapin vRanger.API.PowerShell -ErrorAction SilentlyContinue)) {
  Add-PSSnapin vRanger.API.PowerShell }

### SCAN THE CLO REPOSITORY AND PULL OUT ALL *FULL* SAVEPOINTS FOR THE 4 "LARGE" VMS INDICATED ###
$VMObject = get-repository | where {$_.name -eq "[REPOSITORYNAME]"} | `
get-repositorysavepoint | `
where { `
($_.vmname -eq "[VM1]" -or `
$_.vmname -eq "[VM2]" -or
$_.vmname -eq "[VM3]" -or
$_.vmname -eq "[VM4]" -and 
$_.SpaceSavingTechTypeID -eq "None" }

### FILTER DOWN THE LIST OF SAVEPOINTS FOR THESE LARGE VMS TO JUST THOSE THAT HAVE 2 OR MORE *FULL* SAVE POINTS ###
$VMsMultiSavePoints = $VMObject | group-object VMname | where { $_.count -ge 2 } | select name

### TAKE THE LIST OF VMS WITH 2 OR MORE *FULL* SAVE POINTS AND CREATE A NEW OBJECT THAT CONTAINS ALL OF THE OBJECT DATA FOR THOSE SAVEPOINTS ###
$VMObjectFiltered = $null
ForEach ($VM in $VMsMultiSavePoints)
{
    $VMObjectFiltered += $VMObject | where {$_.vmName -eq $VM.name}
}

if($VMObjectFiltered -ne $null)
{
    ### TAKE THE LIST THAT CONTAINS ALL LARGE VMS WITH 2 OR MORE SAVEPOINTS AND INCLUDE ONLY THE OLDEST SAVEPOINT OF THE GROUP FOR EACH VM ###
    ### NOTE THAT IF THE VM HAS MORE THAN 2 FULL SAVEPOINTS, ONLY THE OLDEST ONE WILL BE DELETED!###
    $VMstoRemove = $VMObjectFiltered | Foreach-Object {$_.EndTime = [DateTime]$_.Endtime; $_} | 
    Group-Object VMName | Foreach-Object {$_.Group | Sort-Object EndTime | Select-Object -First 1}
}

# IF SAVEPOINTS FOUND TO REMOVE, REMOVE THEM NOW
if ($VMstoremove -ne $Null) {
    Remove-SavePoint -SavePointsToRemove $VMsToRemove
}

1 comments

    • abc on February 29, 2016 at 12:53 pm
    • Reply

    thanks.. but we cna’t see the script

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.