New-AzRecoveryServicesBackupProtectionPolicy
Creates 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
New-AzRecoveryServicesBackupProtectionPolicy
[-Name] <String>
[-WorkloadType] <WorkloadType>
[[-BackupManagementType] <BackupManagementType>]
[[-RetentionPolicy] <RetentionPolicyBase>]
[[-SchedulePolicy] <SchedulePolicyBase>]
[-VaultId <String>]
[-DefaultProfile <IAzureContextContainer>]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
Description
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.
Examples
Example 1: Create a Backup protection policy
$SchPol = Get-AzRecoveryServicesBackupSchedulePolicyObject -WorkloadType "AzureVM"
$SchPol.ScheduleRunTimes.Clear()
$Dt = Get-Date
$SchPol.ScheduleRunTimes.Add($Dt.ToUniversalTime())
$RetPol = Get-AzRecoveryServicesBackupRetentionPolicyObject -WorkloadType "AzureVM"
$RetPol.DailySchedule.DurationCountInDays = 365
New-AzRecoveryServicesBackupProtectionPolicy -Name "NewPolicy" -WorkloadType AzureVM -RetentionPolicy $RetPol -SchedulePolicy $SchPol
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
$schedulePolicy = Get-AzRecoveryServicesBackupSchedulePolicyObject -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 = Get-AzRecoveryServicesBackupRetentionPolicyObject -WorkloadType AzureFiles -BackupManagementType AzureStorage -ScheduleRunFrequency Hourly
$retentionPolicy.DailySchedule.DurationCountInDays = 10
New-AzRecoveryServicesBackupProtectionPolicy -Name "NewPolicy" -WorkloadType AzureVM -RetentionPolicy $retentionPolicy -SchedulePolicy $schedulePolicy
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)
New-AzRecoveryServicesBackupProtectionPolicy -Name 'NewPolicy' -RetentionPolicy $RetPol -SchedulePolicy $SchPol -VaultId $vault.ID -WorkloadType AzureVM
Parameters
The class of resources being protected. The acceptable values for this parameter are:
- AzureVM
- AzureStorage
- AzureWorkload
| Type: | Nullable<T>[BackupManagementType] |
| Accepted values: | AzureVM, AzureStorage, AzureWorkload |
| Position: | 3 |
| Default value: | None |
| Accept pipeline input: | True |
| Accept wildcard characters: | False |
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 |
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 |
Specifies the name of the policy.
| Type: | String |
| Position: | 1 |
| Default value: | None |
| Accept pipeline input: | False |
| Accept wildcard characters: | False |
Specifies the base RetentionPolicy object. You can use the Get-AzRecoveryServicesBackupRetentionPolicyObject cmdlet to get a RetentionPolicy object.
| Type: | RetentionPolicyBase |
| Position: | 4 |
| Default value: | None |
| Accept pipeline input: | True |
| Accept wildcard characters: | False |
Specifies the base SchedulePolicy object. You can use the Get-AzRecoveryServicesBackupSchedulePolicyObject cmdlet to get a SchedulePolicy object.
| Type: | SchedulePolicyBase |
| Position: | 5 |
| Default value: | None |
| Accept pipeline input: | True |
| Accept wildcard characters: | False |
ARM ID of the Recovery Services Vault.
| Type: | String |
| Position: | Named |
| Default value: | None |
| Accept pipeline input: | True |
| Accept wildcard characters: | False |
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 |
Workload type of the resource. The acceptable values for this parameter are:
- AzureVM
- AzureFiles
- MSSQL
| Type: | WorkloadType |
| Accepted values: | AzureVM, AzureFiles, MSSQL |
| Position: | 2 |
| Default value: | None |
| Accept pipeline input: | True |
| Accept wildcard characters: | False |
Inputs
Nullable<T>[[Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models.BackupManagementType, Microsoft.Azure.PowerShell.Cmdlets.RecoveryServices.Backup.Models, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]