PowerShell script exchange
Post Reply
amccloud
Service Provider
Posts: 10
Liked: never
Joined: Sep 27, 2018 4:47 pm
Full Name: Anthony McCloud
Contact:

Decrease Retention by current value -1

Post by amccloud »

I have a job created by my predecessor configured to backup a single VM and retain 365 simple retention points. Now it needs to change to 30 days simple with a GFS copy to handle weeklys and monthlys.

If I change the retention on the current job, it will remove all restore points previous to the new setting, and we can’t lose a years worth of backups.

If I disable the current job and make a new one, the old job will never run again, therefore data won’t be aged out (unlike another backup product I use, Data Aging is not a separate process that runs independent of jobs).

So this is a problem. I need the old data to age off normally AND have a Copy job doing GFS.

Having spoken with Veeam Support, their suggestion was keep the existing job, make the copy job for GFS, then create a Powershell script that runs post-thaw to reduce the jobs retention settings by n-1.

So here's what I have so far - this will set retention to a static value by replacing #current value minus 1# with an integer like 7 or 14. What I can't figure out is how to set the variable to itself-1. Any assistance?

Code: Select all

Add-PSSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue
$Job = Get-VBRJob -Name 'job name'
$JobOptions = Get-VBRJobOptions $job
$JobOptions.BackupStorageOptions.RetainCycles = #current value minus 1#
Set-VBRJobOptions -job $Job -Options $JobOptions
jhoughes
Veeam Vanguard
Posts: 279
Liked: 112 times
Joined: Apr 20, 2017 4:19 pm
Full Name: Joe Houghes
Location: Castle Rock, CO
Contact:

Re: Decrease Retention by current value -1

Post by jhoughes »

The value returned is an integer, so just set it to itself minus 1, literally:

Code: Select all

Add-PSSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue
$Job = Get-VBRJob -Name 'job name'
$JobOptions = Get-VBRJobOptions $job
$JobOptions.BackupStorageOptions.RetainCycles = ($JobOptions.BackupStorageOptions.RetainCycles - 1)
Set-VBRJobOptions -job $Job -Options $JobOptions
Husband, Father, Solutions Architect, Geek Extraordinaire | @DenverVMUG, @AustinVMUG & @ATXPowerShell leader | VMware vExpert | Cisco Champion
amccloud
Service Provider
Posts: 10
Liked: never
Joined: Sep 27, 2018 4:47 pm
Full Name: Anthony McCloud
Contact:

Re: Decrease Retention by current value -1

Post by amccloud »

Much appreciated! Thanks, this works exactly as intended. Now I've worked in some if logic to stop decrementing when the total restore points equals 31.

Code: Select all

Add-PSSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue
$Job = Get-VBRJob -Name 'job name'
$JobOptions = Get-VBRJobOptions $job
if ($JobOptions.BackupStorageOptions.RetainCycles -gt 31) 
{
    $JobOptions.BackupStorageOptions.RetainCycles = ($JobOptions.BackupStorageOptions.RetainCycles - 1)
    Set-VBRJobOptions -job $Job -Options $JobOptions
}

Post Reply

Who is online

Users browsing this forum: No registered users and 18 guests