To create an enhanced backup policy or update the policy, run the following cmdlets:
Step 1: Create the backup policy
$SchPol = Get-AzRecoveryServicesBackupSchedulePolicyObject -PolicySubType "Enhanced" -WorkloadType "AzureVM" -ScheduleRunFrequency “Hourly”
The parameter ScheduleRunFrequency:Hourly
now also be an acceptable value for Azure VM workload.
Also, the output object for this cmdlet contains the following additional fields for Azure VM workload, if you're creating hourly policy.
[-ScheduleWindowStartTime <DateTime>]
[-ScheduleRunTimezone <String>]
[-ScheduleInterval <Int>]
[-ScheduleWindowDuration <Int>]
Step 2: Set the backup schedule objects
$schedulePolicy = Get-AzRecoveryServicesBackupSchedulePolicyObject -WorkloadType AzureVM -BackupManagementType AzureVM -PolicySubType Enhanced -ScheduleRunFrequency Hourly
$timeZone = Get-TimeZone -ListAvailable | Where-Object { $_.Id -match "India" }
$schedulePolicy.ScheduleRunTimeZone = $timeZone.Id
$windowStartTime = (Get-Date -Date "2022-04-14T08:00:00.00+00:00").ToUniversalTime()
$schPol.HourlySchedule.WindowStartTime = $windowStartTime
$schedulePolicy.HourlySchedule.ScheduleInterval = 4
$schedulePolicy.HourlySchedule.ScheduleWindowDuration = 23
In this sample cmdlet:
The first command gets a base enhanced hourly SchedulePolicyObject for WorkloadType AzureVM, and then stores it in the $schedulePolicy variable.
The second and third command fetches the India timezone and updates the timezone in the $schedulePolicy.
The fourth and fifth command initializes the schedule window start time and updates the $schedulePolicy.
[Note]
The start time must be in UTC even if the timezone is not UTC.
The sixth and seventh command updates the interval (in hours) after which the backup will be retriggered on the same day, duration (in hours) for which the schedule will run.
Step 3: Create the backup retention policy
Get-AzRecoveryServicesBackupRetentionPolicyObject -WorkloadType AzureVM -ScheduleRunFrequency "Hourly"
- The parameter
ScheduleRunFrequency:Hourly
is also an acceptable value for Azure VM workload.
- If
ScheduleRunFrequency
is hourly, you don't need to enter a value for RetentionTimes
to the policy object.
Step 4: Set the backup retention policy object
$RetPol.DailySchedule.DurationCountInDays = 365
Step 5: Save the policy configuration
AzRecoveryServicesBackupProtectionPolicy
New-AzRecoveryServicesBackupProtectionPolicy -Name "NewPolicy" -WorkloadType AzureVM -RetentionPolicy $RetPol -SchedulePolicy $SchPol
For Enhanced policy, the allowed values for snapshot retention are from 1 day to 30 days.
Note
The specific value depends on the hourly frequency. For example, when hourly frequency is 4 hours, the maximum retention allowed is 17 days, for 6 hours it is 22 days. Let's add this specific information here.
Step 6: Update snapshot retention duration
$bkpPol = Get-AzRecoveryServicesBackupProtectionPolicy -Name "NewPolicy"
$bkpPol.SnapshotRetentionInDays=10
Set-AzRecoveryServicesBackupProtectionPolicy -policy $bkpPol -VaultId <VaultId>
List enhanced backup policies
To view the existing enhanced policies, run the following cmdlet:
Get-AzRecoveryServicesBackupProtectionPolicy -PolicySubType "Enhanced"
For Get-AzRecoveryServicesBackupProtectionPolicy
:
- Add the parameter
PolicySubType
. The allowed values are Enhanced
and Standard
. If you don't specify a value for this parameter, all policies (standard and enhanced) get listed.
- The applicable parameter sets are
NoParamSet
, WorkloadParamSet
, WorkloadBackupManagementTypeParamSet
.
- For non-VM workloads, allowed value is
Standard
only.
Note
You can retrieve the sub type of policies. To list Standard backup policies, specify Standard
as the value of this parameter. To list Enhanced backup policies for Azure VMs, specify Enhanced
as the value of this parameter.
To configure backup of a Trusted launch VM or assign a new policy to the VM, run the following cmdlet:
$targetVault = Get-AzRecoveryServicesVault -ResourceGroupName "Contoso-docs-rg" -Name "testvault"
$pol = Get-AzRecoveryServicesBackupProtectionPolicy -Name "NewPolicy" -VaultId $targetVault.ID
Enable-AzRecoveryServicesBackupProtection -Policy $pol -Name "V2VM" -ResourceGroupName "RGName1" -VaultId $targetVault.ID
To create an enhanced backup policy, run the following command:
az backup policy create --policy {policy} --resource-group MyResourceGroup --vault-name MyVault --name MyPolicy --backup-management-type AzureIaaSVM -PolicySubType "Enhanced"
Policy is passed in JSON format to the create command.
Update an enhanced backup policy
To update an enhanced backup policy, run the following command:
az backup policy set --policy {policy} --resource-group MyResourceGroup --vault-name MyVault -PolicySubType "Enhanced"
List enhanced backup policies
To list all existing enhanced policies, run the following command:
az backup policy list --resource-group MyResourceGroup --vault-name MyVault --policy-sub-type Enhanced --workload-type VM
For parameter –policy-sub-type
, the allowed values are Enhanced
and Standard
. If you don't specify a value for this parameter, all policies (standard and enhanced) get listed.
For non-VM workloads, the only allowed value is Standard
To configure backup for a VM or assign a new policy to the VM, run the following command:
az backup protection enable-for-vm \
--resource-group myResourceGroup \
--vault-name myRecoveryServicesVault \
--vm $(az vm show -g VMResourceGroup -n MyVm --query id | tr -d '"') \
--policy-name DefaultPolicy
Trusted Launch VMs can only be backed up using Enhanced policies.
Note
- Currently, a non-Trusted Launch VM that was earlier using Standard policy can't start using Enhanced policy.
- A VM that is using Enhanced policy can't be updated to use Standard policy.