PowerShell script exchange
Post Reply
maanlicht
Enthusiast
Posts: 32
Liked: 6 times
Joined: Apr 05, 2023 1:06 pm
Full Name: maanlicht
Contact:

Managing GFS policys with powershell

Post by maanlicht »

Dear Veeam community,

It appears we could use some clarification on how to manage GFS trough powershell for backupCopy jobs. In my use case I would like to use powershell to enable GFS for a copyjob that currently is set to a ‘simple’ retention policy.

On first glance I found the ‘New-VBRGFSRetentionPolicy’ and the ‘Set-VBRGFSRetentionPolicy’ commands in the documentation that seemed promising and are geared for copyjobs.

However the ‘Set-VBRGFSRetentionPolicy’ only seem to allow me to modfy a GFS policy if GFS was already enabled because if I do it returns the error:

Code: Select all

$job = Get-VBRBackupCopyJob -Name 'LAB2 - Backup Copy'
$policy = Get-VBRRetentionPolicy -Job $job 
Set-VBRGFSRetentionPolicy -RetentionPolicy $policy -RestorePoints 5 -GFSWeeklyBackups 8 -GFSMonthlyBackups 4 -GFSYearlyBackups 9 
Set-VBRGFSRetentionPolicy : Cannot bind parameter 'RetentionPolicy'. Cannot convert the "Veeam.Backup.PowerShell.Infos.VBRSimpleRetentionPolicy" value of type "Veeam.Backup.PowerShell.Infos.VBRSimpleRetentionPolicy" to type
"Veeam.Backup.PowerShell.Infos.VBRGFSRetentionPolicy".

So I assume I have to use the ‘New-VBRGFSRetentionPolicy’ command to create a new policy. However there appears to be no way to target the new policy object to a particular job. If I ran the following code, how would it know what job to apply it to?

Code: Select all

$policy = New-VBRGFSRetentionPolicy -RestorePoints 2 -GFSWeeklyBackups 3 -GFSMonthlyBackups 4 -GFSQuarterlyBackups 5 -GFSYearlyBackups 9 
Set-VBRGFSRetentionPolicy -RetentionPolicy $policy
From my perspective this appears to render the ‘New-VBRGFSRetentionPolicy’ command useless. I am sure that is not the case.. but what am I missing? Can you please point us in the right direction?

Thanks in advance!
maanlicht
Enthusiast
Posts: 32
Liked: 6 times
Joined: Apr 05, 2023 1:06 pm
Full Name: maanlicht
Contact:

Re: Managing GFS policys with powershell

Post by maanlicht » 1 person likes this post

Found the solution! For anyone running into this in the future, the following code worked for me:

Code: Select all

$job = Get-VBRBackupCopyJob -name 'LAB2 - Backup Copy'
$weekly = New-VBRComputerGFSWeeklyOptions -RetentionPeriod 3 -SelectedDay Wednesday
$monthly = New-VBRComputerGFSMonthlyOptions -RetentionPeriod 3 -SelectedWeek First
$yearly = New-VBRComputerGFSYearlyOptions -RetentionPeriod 2 -SelectedMonth November
$options = New-VBRComputerGFSOptions -GFSWeeklyOptions $weekly -GFSMonthlyOptions $monthly -GFSYearlyOptions $yearly

$job | Set-VBRBackupCopyJob -GFSOptions $options
Cheers!
david.domask
Veeam Software
Posts: 2644
Liked: 613 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Managing GFS policys with powershell

Post by david.domask »

Hi maanlicht,

[Moderator Edit: Oh! you found it as I was writing my post :D Cool))]


The cmdlets you found are for External Repositories (e.g., repositories added to Veeam Backup and Replication Server (VBR) from Veeam Backup for AWS/Azure/GCP), so they won't apply to your regular Backup Copies. (Check the page here, you'll see it's under the EC2 backup copies: https://helpcenter.veeam.com/docs/backu ... ml?ver=120)

The correct way is a bit confusing due to the cmdlet names, but see the User Guide page on Set-VBRBackupCopyJob:
GFSOptions

Specifies a GFS retention. The cmdlet will create a backup copy job with the specified policy.

Accepts the VBRComputerGFSOptions object. To get this object, run the New-VBRComputerGFSOptions cmdlet.
So you will use New-VBRComputerGFSOptions and create the necessary policy as the cmdlet page tells (note you need to make individual objects for Weekly/Monthly/Yearly), then pass that on the -GFSOptions flag for Set-VBRBackupCopyJob.
David Domask | Product Management: Principal Analyst
maanlicht
Enthusiast
Posts: 32
Liked: 6 times
Joined: Apr 05, 2023 1:06 pm
Full Name: maanlicht
Contact:

Re: Managing GFS policys with powershell

Post by maanlicht »

Thanks for your feedback!

This method allows us to 'enable' GFS. This leads us to the logical follow-up question.. how do we disable it?
david.domask
Veeam Software
Posts: 2644
Liked: 613 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Managing GFS policys with powershell

Post by david.domask »

Hi maanlicht,

Create an empthy New-VBRComputerGFSOptions object, then set that on the -GFSOptions parameter of Set-VBRBackupCopy. This will remove the GFS periods and disable the weekly/monthly/yearly.

A note, there is a bit of strangeness in that the UI will still show the "Keep certain backups longer for archival purposes" checked, but no GFS policy will be configured; I'm not sure if this is expected so let me look into that, but setting it as above will effectively disable GFS for a given Backup Copy Job.

Remember, this will effectively set the GFS retention to 0, which means retention will understand that no GFS points for that period should be kept. Powershell will warn you about this before you apply it:

Code: Select all

PS C:\Users\david.LAB> Set-VBRBackupCopyJob -Job $bcj -GFSOptions $GFSopts
GFS retention warning
You are about to apply the modified GFS retention policy. One or several existing GFS backups will be removed. Proceed
anyway ?
[Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"): Y
David Domask | Product Management: Principal Analyst
maanlicht
Enthusiast
Posts: 32
Liked: 6 times
Joined: Apr 05, 2023 1:06 pm
Full Name: maanlicht
Contact:

Re: Managing GFS policys with powershell

Post by maanlicht »

Yes I understand. Thanks for your reply!
The only problem with that solution is that as long as the GFS checkbox is still enabled we would not be able to do any 'defrag and compacting' right?
david.domask
Veeam Software
Posts: 2644
Liked: 613 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Managing GFS policys with powershell

Post by david.domask »

Hi maanlicht,

Yes, I believe you're correct on that and I'm checking internally on the expectedness of this situation; I will update as it doesn't look correct at first blush, but I may be missing something obvious on how this should be handled.
David Domask | Product Management: Principal Analyst
maanlicht
Enthusiast
Posts: 32
Liked: 6 times
Joined: Apr 05, 2023 1:06 pm
Full Name: maanlicht
Contact:

Re: Managing GFS policys with powershell

Post by maanlicht »

After some more digging I found that for agent jobs this can be easely controlled. The 'Set-VBRComputerBackupJob' command has an '-EnableGFSRetention' switch wich appears to be missing for 'Set-VBRBackupCopyJob'
Post Reply

Who is online

Users browsing this forum: No registered users and 25 guests