Set-AzRecoveryServicesBackupProtectionPolicy

Modifies a Backup protection policy.

Note

This is the previous version of our documentation. Please consult the most recent version for up-to-date information.

Syntax

Set-AzRecoveryServicesBackupProtectionPolicy
   [-Policy] <PolicyBase>
   [[-RetentionPolicy] <RetentionPolicyBase>]
   [[-SchedulePolicy] <SchedulePolicyBase>]
   [-VaultId <String>]
   [-DefaultProfile <IAzureContextContainer>]
   [-WhatIf]
   [-Confirm]
   [<CommonParameters>]
Set-AzRecoveryServicesBackupProtectionPolicy
   [-Policy] <PolicyBase>
   [-FixForInconsistentItems]
   [-VaultId <String>]
   [-DefaultProfile <IAzureContextContainer>]
   [-WhatIf]
   [-Confirm]
   [<CommonParameters>]

Description

The Set-AzRecoveryServicesBackupProtectionPolicy cmdlet modifies an existing Azure Backup protection policy. You can modify the Backup schedule and retention policy components. Any changes you make affect the backup and retention of the items associated with the policy. Set the vault context by using the Set-AzRecoveryServicesVaultContext cmdlet before you use the current cmdlet.

Examples

Example 1: Modify a Backup protection policy

$SchPol = Get-AzRecoveryServicesBackupSchedulePolicyObject -WorkloadType "AzureVM" 
$SchPol.ScheduleRunTimes.Clear()
$Time = Get-Date
$Time1 = Get-Date -Year $Time.Year -Month $Time.Month -Day $Time.Day -Hour $Time.Hour -Minute 0 -Second 0 -Millisecond 0
$Time1 = $Time1.ToUniversalTime()
$SchPol.ScheduleRunTimes.Add($Time1)
$SchPol.ScheduleRunFrequency.Clear
$SchPol.ScheduleRunDays.Add("Monday")
$SchPol.ScheduleRunFrequency="Weekly"
$RetPol = Get-AzRecoveryServicesBackupRetentionPolicyObject -WorkloadType "AzureVM" 
$RetPol.IsDailyScheduleEnabled=$false
$RetPol.DailySchedule.DurationCountInDays = 0
$RetPol.IsWeeklyScheduleEnabled=$true 
$RetPol.WeeklySchedule.DaysOfTheWeek.Add("Monday")
$RetPol.WeeklySchedule.DurationCountInWeeks = 365
$vault = Get-AzRecoveryServicesVault -ResourceGroupName "azurefiles" -Name "azurefilesvault"
$Pol= Get-AzRecoveryServicesBackupProtectionPolicy -Name "TestPolicy" -VaultId $vault.ID
$Pol.SnapshotRetentionInDays=5
Set-AzRecoveryServicesBackupProtectionPolicy -Policy $Pol -SchedulePolicy $SchPol -RetentionPolicy $RetPol

Here is the high-level description of the steps to be followed for modifying a protection policy:

  1. Get a base SchedulePolicyObject and base RetentionPolicyObject. Store them in some variable.
  2. Set the different parameters of schedule and retention policy object as per your requirement. For example- In the above sample script, we are trying to set a weekly protection policy. Hence, we changed the schedule frequency to "Weekly" and also updated the schedule run time. In the retention policy object, we updated the weekly retention duration and set the correct "weekly schedule enabled" flag. In case you want to set a Daily policy, set the "daily schedule enabled" flag to true and assign appropriate values for other object parameters.
  3. Get the backup protection policy that you want to modify and store it in a variable. In the above example, we retrieved the backup policy with the name "TestPolicy" that we wanted to modify.
  4. Modify the backup protection policy retrieved in step 3 using the modified schedule policy object and retention policy object.

Example 2: Modify Azure fileshare policy for multiple backups per day

$schedulePolicy = Get-AzRecoveryServicesBackupSchedulePolicyObject -WorkloadType AzureFiles -BackupManagementType AzureStorage -ScheduleRunFrequency Hourly
$retentionPolicy = Get-AzRecoveryServicesBackupRetentionPolicyObject -WorkloadType AzureFiles -BackupManagementType AzureStorage -ScheduleRunFrequency Hourly
$timeZone = Get-TimeZone
$schedulePolicy.ScheduleRunTimeZone = $timeZone.Id
$startTime = Get-Date -Date "2021-12-22T06:00:00.00+00:00"
$schedulePolicy.ScheduleWindowStartTime = $startTime.ToUniversalTime()
$schedulePolicy.ScheduleInterval = 6
$schedulePolicy.ScheduleWindowDuration = 14
$retentionPolicy.DailySchedule.DurationCountInDays = 6
$policy = Get-AzRecoveryServicesBackupProtectionPolicy -Name "TestPolicy" -VaultId $vault.ID
Set-AzRecoveryServicesBackupProtectionPolicy -Policy $policy -VaultId $vault.ID -SchedulePolicy $schedulePolicy -RetentionPolicy $retentionPolicy

Here is the high-level description of the steps to be followed for modifying a fileshare policy for multiple backups per day:

  1. Get a base hourly SchedulePolicyObject and base hourly RetentionPolicyObject. Store them in some variable.
  2. Set the different parameters of schedule and retention policy object as per your requirement. For example- In the above sample script, we are trying to set the $timeZone in which we want to run the schedule we are setting the start time of the Hourly schedule, setting hourly interval (in hours), after which the backup will be retriggered on the same day, duration (in hours) for which the schedule will run. Next we are modifying the retention setting for daily recovery points.
  3. Get the backup protection policy that you want to modify and store it in a variable. In the above example, we retrieved the backup policy with the name "TestPolicy" that we wanted to modify.
  4. Modify the backup protection policy retrieved in step 3 using the modified schedule policy object and retention policy object.

Parameters

-Confirm

Prompts you for confirmation before running the cmdlet.

Type:SwitchParameter
Aliases:cf
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-DefaultProfile

The credentials, account, tenant, and subscription used for communication with azure.

Type:IAzureContextContainer
Aliases:AzContext, AzureRmContext, AzureCredential
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-FixForInconsistentItems

Switch Parameter indicating whether or not to retry Policy Update for failed items.

Type:SwitchParameter
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-Policy

Specifies the Backup protection policy that this cmdlet modifies. To obtain a BackupProtectionPolicy object, use the Get-AzRecoveryServicesBackupProtectionPolicy cmdlet.

Type:PolicyBase
Position:1
Default value:None
Accept pipeline input:True
Accept wildcard characters:False
-RetentionPolicy

Specifies the base retention policy. To obtain a RetentionPolicy object, use the Get-AzRecoveryServicesBackupRetentionPolicyObject cmdlet.

Type:RetentionPolicyBase
Position:2
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-SchedulePolicy

Specifies the base schedule policy object. To obtain a SchedulePolicy object, use the Get-AzRecoveryServicesBackupSchedulePolicyObject object.

Type:SchedulePolicyBase
Position:3
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-VaultId

ARM ID of the Recovery Services Vault.

Type:String
Position:Named
Default value:None
Accept pipeline input:True
Accept wildcard characters:False
-WhatIf

Shows what would happen if the cmdlet runs.

Type:SwitchParameter
Aliases:wi
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False

Inputs

PolicyBase

String

Outputs

JobBase