The New-AzRecoveryServicesBackupProtectionPolicy cmdlet creates a Backup protection policy in a vault.
A protection policy is associated with at least one retention policy.
The retention policy defines how long a recovery point is kept with Azure Backup.
You can use the Get-AzRecoveryServicesBackupRetentionPolicyObject cmdlet to get the default retention policy.
And you can use the Get-AzRecoveryServicesBackupSchedulePolicyObject cmdlet to get the default schedule policy.
The SchedulePolicy and RetentionPolicy objects are used as inputs to the New-AzRecoveryServicesBackupProtectionPolicy cmdlet.
Set the vault context by using the Set-AzRecoveryServicesVaultContext cmdlet before you use the current cmdlet.
The first command gets a base SchedulePolicyObject, and then stores it in the $SchPol variable.
The second command removes all scheduled run times from the schedule policy in $SchPol.
The third command uses the Get-Date cmdlet to get the current date and time.
The fourth command adds the current date and time in $Dt as the scheduled run time to the schedule policy.
The fifth command gets a base RetentionPolicy object, and then stores it in the $RetPol variable.
The sixth command sets the retention duration policy to 365 days.
The final command creates a BackupProtectionPolicy object based on the schedule and retention policies created by the previous commands.
Example 2: Create a fileshare policy for multiple backups per day
The first command gets a base hourly SchedulePolicyObject, and then stores it in the $schedulePolicy variable.
The second and third command fetches the timezone and updates the timezone in the $schedulePolicy.
The fourth and fifth command initializes the schedule window start time and updates the $schedulePolicy. Please 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.
The eighth command gets a base hourly RetentionPolicy object, and then stores it in the $retentionPolicy variable.
The ninth command sets the retention duration policy to 10 days.
The final command creates a BackupProtectionPolicy object based on the schedule and retention policies created by the previous commands.
Example 3
Creates a Backup protection policy. (autogenerated)
This command is used to create policy to enable archive smart tiering for tiering mode TierRecommended, we set -MoveToArchiveTier parameter to $true to enable smart tiering. We set TieringMode to TierRecommended to move all recommended recovery points to archive. Please note that tiering mode TierRecommended is only supported for workload type AzureVM.
Example 5: Create new policy with archive smart tiering disabled
The first command gets a SchedulePolicyObject, and then stores it in the $schedulePolicy variable.
The second command block fetches the timezone and datetime (localtime marked as UTC) and updates the timezone and time in the $schedulePolicy. Please note that the datetime should always be marked as UTC as the timezone is given separately. Also note, for other workload types timezone should be given in $schedulePolicy.ScheduleRunTimeZone attribute.
The third command block updates the Differential schedule policy.
Then, we get the RetentionPolicyObject and update differential and full backup retention settings.
Finally we create a BackupProtectionPolicy object based on the schedule and retention policies created by the previous commands.
Parameters
-BackupManagementType
The class of resources being protected. The acceptable values for this parameter are:
Snapshot consistency type to be used for backup. If set to OnlyCrashConsistent, all associated items will have crash consistent snapshot. Possible values are OnlyCrashConsistent, Default
Specifies the duration after which recovery points should start moving to the archive tier, value can be in days or months. Applicable only when TieringMode is TierAllEligible
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable,
-InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable,
-ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see
about_CommonParameters.
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.