PowerShell script exchange
Post Reply
griffiq
Lurker
Posts: 2
Liked: never
Joined: Apr 24, 2018 7:29 pm
Contact:

Change Retention Policy for All Jobs

Post by griffiq »

Please Help! If I do this manually it will take forever. I need to change the retention period on over 300 jobs. I run the command below in bold but the actual retention period never changes and no errors reported. The ultimate goal is to set all jobs Retention Policy to 31 days. Thanks in advance.

The command I’m using to try on one job – Job name is "PSTest"

Code: Select all

[b]Get-VBRJob -Name "PSTest" | Set-VBRJobAdvancedOptions -RetainDays 31[/b]


This is the entire command and output:

[i]PS C:\Windows\system32> Get-VBRJob -Name "PSTest" | Set-VBRJobAdvancedOptions -RetainDays 31


FreeBackupImpl               :
IsFree                       : False
UserCryptoKey                :
Id                           : ffc36b3f-8e3a-4fcb-a3c9-ce78b4287086
Info                         : Veeam.Backup.Model.CDbBackupJobInfo
JobType                      : Backup
SourceType                   : VDDK
JobTargetType                : Backup
TargetType                   : Other
TypeToString                 : VMware Backup
Description                  : Test Description
Name                         : PSTest
BackupPlatform               : EVmware
TargetHostId                 : 5de8c30c-7d80-42cb-961c-bacecc033469
TargetDir                    : /home/VeeamExaGrid/VeeamRepository01/Repository
TargetFile                   : PSTest
Options                      : Veeam.Backup.Model.CJobOptions
IsContinuous                 : False
NameWithDescription          : PSTest (Test Description)
SqlEnabled                   : False
OracleEnabled                : False
ParentJobId                  :
HvReplicaTargetOptions       : Veeam.Backup.Model.CDomHvReplicaTargetOptions
BackupStorageOptions         : Veeam.Backup.Model.CDomBackupStorageOptions
BackupTargetOptions          : Veeam.Backup.Model.CDomBackupTargetOptions
HvSourceOptions              : Veeam.Backup.Model.CDomHvSourceOptions
NotificationOptions          : Veeam.Backup.Model.CDomNotificationOptions
JobScriptCommand             : Veeam.Backup.Model.CDomJobScriptCommand
ViReplicaTargetOptions       : Veeam.Backup.Model.CDomViReplicaTargetOptions
CloudReplicaTargetOptions    : Veeam.Backup.Model.CDomCloudReplicaTargetOptions
ViSourceOptions              : Veeam.Backup.Model.CDomViSourceOptions
VssOptions                   : VssSnapshotOptions: [Enabled: [False], IgnoreErrors: [False], IsCopyOnly: [False]], WinGuestFSIndexingOptions: [Type: [None]], LinGuestFSIndexingOptions: [Type: [None]], SqlBackupOptions: [TransactionLogsProcessing:
                               [TruncateOnlyOnSuccessJob], BackupLogsFrequencyMin: [15], UseDbBackupRetention: [True], RetainDays: [15], ProxyAutoSelect: [True]], ExchangeBackupOptions: [TransactionLogsProcessing: [TruncateOnlyOnSuccessJob]], WinCredsId:
                               [00000000-0000-0000-0000-000000000000], LinCredsId: [00000000-0000-0000-0000-000000000000], Old Properties: [Enabled: [False], IgnoreErrors: [False], GuestFSIndexingType: [None], IncludedIndexingFolders: [], ExcludedIndexingFolders: [],
                               LinGuestFSIndexingType: [None], LinIncludedIndexingFolders: [], LinExcludedIndexingFolders: [], IsFirstUsage: [True]]
ScheduleOptions              : Start time: [2/9/2018 10:00:00 PM], Latest run time: [4/23/2018 10:00:09 PM], Timeout for backup completion: [180min], Next run time: [04/24/2018 22:00:00], Retry times on failure: [1], Retry timeout: [60 min], Daily options: [Enabled:
                               True, DayNumberInMonth: Everyday, Days: Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday]
IsRunning                    : False
IsRequireRetry               : False
IsIdle                       : False
IsScheduleEnabled            : True
SourceProxyAutoDetect        : True
IsInitialReplica             : False
IsMappingReplica             : False
IsBackup                     : True
IsBackupSync                 : False
IsSnapshotReplica            : False
IsLegacyReplica              : False
IsReplica                    : False
IsVmCopy                     : False
IsTapeBackup                 : False
IsFileTapeBackup             : False
IsVmTapeBackup               : False
SourceWanAcceleratorName     :
TargetWanAcceleratorName     :
LinkedJobs                   : {}
LinkedJobIds                 : {}
LinkedRepositories           : {}
LinkedRepositoryIds          : {}
IsForeverIncremental         : False
IsBackupJob                  : True
IsEndpointJob                : False
SheduleEnabledTime           :
AutoScheduleOptions          : Veeam.Backup.Model.CAutoScheduleOptions
PreviousJobIdInScheduleChain :



PS C:\Windows\system32>
[/i]
veremin
Product Manager
Posts: 20397
Liked: 2298 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Change Retention Policy for All Jobs

Post by veremin » 3 people like this post

Try the following example and see whether it helps:

Code: Select all

Asnp VeeamPSSnapin
$Jobs = Get-VBRJob | where {$_.Jobtype -eq "Backup"}
foreach ($Job in $Jobs)
{
$Options = $Job.GetOptions()
$Options.backupstorageoptions.retaincycles = 30
Set-VBRJobOptions -Job $Job -Options $Options
}
Thanks.
griffiq
Lurker
Posts: 2
Liked: never
Joined: Apr 24, 2018 7:29 pm
Contact:

Re: Change Retention Policy for All Jobs

Post by griffiq »

Thanks v.Eremin for your reply! That worked like a charm!!! Thanks very much :) You saved me hours and literally thousands of clicks!
veremin
Product Manager
Posts: 20397
Liked: 2298 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Change Retention Policy for All Jobs

Post by veremin »

You're welcome.

When you want to change some job settings via PowerShell, you need to:

1) Assign job to a variable
2) Get job settings, using GetOptions() method
3) Assign job settings to a variable
4) Within job settings variable find a property you want to change
5) Modify it
6) Pass modified job settings variable Set-VBRJobOptions cmdlet

Thanks.
Kayra
Novice
Posts: 3
Liked: never
Joined: Feb 15, 2019 10:22 am
Full Name: Kayra Ali
Contact:

Re: Change Retention Policy for All Jobs

Post by Kayra »

Hi v.Eremin,

How would you translate this to change "restore points to keep" for all Backup Copy jobs?

Will changing
- jobtype to BackupSync
and
- Options.backupstorageoptions.retaincycles to GenerationPolicy.SimpleRetentionRestorePoints
work?

Thx in advance.
veremin
Product Manager
Posts: 20397
Liked: 2298 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Change Retention Policy for All Jobs

Post by veremin »

Yes, you're correct. Thanks!
Post Reply

Who is online

Users browsing this forum: No registered users and 15 guests