PowerShell script exchange
Post Reply
Luca Marohn
Service Provider
Posts: 8
Liked: 5 times
Joined: Feb 11, 2020 12:15 pm
Full Name: Luca Marohn
Contact:

Setting retention policy does not work

Post by Luca Marohn »

Hi

I'm trying to setup a Hyper-V backup job rentetion with powershell. As seen online it shouldn't be that complicated but I'm not getting it to work. The goal is to have a retention policy for 30 days (not restore points) and a GFS policy for 8 weeks, 12 months, 5 years. The script part looks like this:

Code: Select all

$options = Get-VBRJobOptions -Job $jobname
$options.BackupStorageOptions.RetainDays = 30
$options.BackupStorageOptions.RetainCycles = 30
$options.GfsPolicy.IsEnabled = $true
$options.GfsPolicy.Weekly.IsEnabled = $true
$options.GfsPolicy.Weekly.KeepBackupsForNumberOfWeeks = 8
$options.GfsPolicy.Monthly.IsEnabled = $true
$options.GfsPolicy.Monthly.KeepBackupsForNumberOfMonths = 12
$options.GfsPolicy.Yearly.IsEnabled = $true
$options.GfsPolicy.Yearly.KeepBackupsForNumberOfYears = 5 

Set-VBRJobOptions -Job $jobname -Options $options
I tried to play with the values of BackupStorageOptions but it just stays on 7 days, which seems to be default value.

Am I missing something particular?

Greetings
Luca
david.domask
Veeam Software
Posts: 2566
Liked: 603 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Setting retention policy does not work

Post by david.domask » 1 person likes this post

Hi @Luca Marohn,

I think you are mostly doing it right but you need to set the argument to flip it from Points to Days:

Code: Select all

$opts.BackupStorageOptions.RetentionType = "Days"
Set-VBRJobOptions -Job $job -Options $Opts
WARNING: Enable periodic fulls, or schedule a script to create them.

Job Name                  Type            State      Last Result  Description
--------                  ----            -----      -----------  -----------
vmware-ffi-cap-bb         VMware Backup   Stopped    Success      Created by DDOM-VEEAM-RB4\deeks at 8/29/2022 11:14...
The BackupStorageOptions property has the RetentionType value, and you can set it to Points or Days (you can use GetType().GetEnumNames() on any property with enums (names) like this and it will show you the possible values of the enum)

Add this in your script and test it, it should flip the jobs to Days then.
David Domask | Product Management: Principal Analyst
Luca Marohn
Service Provider
Posts: 8
Liked: 5 times
Joined: Feb 11, 2020 12:15 pm
Full Name: Luca Marohn
Contact:

Re: Setting retention policy does not work

Post by Luca Marohn »

Hi David

Thank you for your input.

Got the script working as following:

Code: Select all

$options = Get-VBRJobOptions -Job $jobname
$options.BackupStorageOptions.RetentionType = "Days"
$options.BackupStorageOptions.RetainDaysToKeep = 30
$options.GfsPolicy.IsEnabled = $true
$options.GfsPolicy.Weekly.IsEnabled = $true
$options.GfsPolicy.Weekly.KeepBackupsForNumberOfWeeks = 8
$options.GfsPolicy.Monthly.IsEnabled = $true
$options.GfsPolicy.Monthly.KeepBackupsForNumberOfMonths = 12
$options.GfsPolicy.Yearly.IsEnabled = $true
$options.GfsPolicy.Yearly.KeepBackupsForNumberOfYears = 5 

Set-VBRJobOptions -Job $jobname -Options $options
Btw, the RetentionType for Restore Points is "Cycles", tested that as well.
david.domask
Veeam Software
Posts: 2566
Liked: 603 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Setting retention policy does not work

Post by david.domask »

Always welcome! Glad it worked @Luca Marohn!

Good luck with the scripting.
David Domask | Product Management: Principal Analyst
Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests