Edit

Share via


New-AzRecoveryServicesBackupProtectionPolicy

Creates a Backup protection policy.

Syntax

Default (Default)

New-AzRecoveryServicesBackupProtectionPolicy
    [-Name] <String>
    [-WorkloadType] <WorkloadType>
    [[-BackupManagementType] <BackupManagementType>]
    [[-RetentionPolicy] <RetentionPolicyBase>]
    [[-SchedulePolicy] <SchedulePolicyBase>]
    [[-MoveToArchiveTier] <Boolean>]
    [[-TieringMode] <TieringMode>]
    [[-TierAfterDuration] <Int32>]
    [[-TierAfterDurationType] <String>]
    [-BackupSnapshotResourceGroup <String>]
    [-BackupSnapshotResourceGroupSuffix <String>]
    [-SnapshotConsistencyType <SnapshotConsistencyType>]
    [-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

Example 4: Create new AzureVM policy to enable Archive smart tiering with TieringMode TierRecommended

$pol = New-AzRecoveryServicesBackupProtectionPolicy -Name newTierRecommendedPolicy -WorkloadType AzureVM -BackupManagementType AzureVM -RetentionPolicy $retPol -SchedulePolicy $schPol -VaultId $vault.ID -MoveToArchiveTier $true -TieringMode TierRecommended

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

$pol = New-AzRecoveryServicesBackupProtectionPolicy -VaultId $vault.ID  -WorkloadType AzureVM -BackupManagementType AzureVM -RetentionPolicy $retPol -SchedulePolicy $schPol -MoveToArchiveTier $false

This command is used to disable archive smart tiering while creating a policy, we set MoveToArchiveTier parameter to $false to disable tiering.

Example 6: Create a non UTC timezone standard policy for workloadType MSSQL

$schedulePolicy = Get-AzRecoveryServicesBackupSchedulePolicyObject -WorkloadType MSSQL -BackupManagementType AzureWorkload -PolicySubType Standard

$timeZone = Get-TimeZone -ListAvailable | Where-Object { $_.Id -match "Tokyo" }
$date= Get-Date -Hour 9 -Minute 0 -Second 0 -Year 2022 -Day 26 -Month 12 -Millisecond 0
$date = [DateTime]::SpecifyKind($date,[DateTimeKind]::Utc)
$schedulePolicy.FullBackupSchedulePolicy.ScheduleRunFrequency = "Weekly"
$schedulePolicy.FullBackupSchedulePolicy.ScheduleRunTimes[0] = $date
$schedulePolicy.FullBackupSchedulePolicy.ScheduleRunTimeZone = $timeZone[0].Id

$schedulePolicy.IsDifferentialBackupEnabled = $true
$schedulePolicy.DifferentialBackupSchedulePolicy.ScheduleRunDays[0] = "Wednesday"
$schedulePolicy.DifferentialBackupSchedulePolicy.ScheduleRunTimes[0] = $date.AddHours(1)

$retentionPolicy = Get-AzRecoveryServicesBackupRetentionPolicyObject -WorkloadType MSSQL -BackupManagementType AzureWorkload

$retentionPolicy.DifferentialBackupRetentionPolicy.RetentionCount = 15

$retentionPolicy.FullBackupRetentionPolicy.IsDailyScheduleEnabled = $false
$retentionPolicy.FullBackupRetentionPolicy.IsMonthlyScheduleEnabled = $false
$retentionPolicy.FullBackupRetentionPolicy.WeeklySchedule.DurationCountInWeeks = 35
$retentionPolicy.FullBackupRetentionPolicy.YearlySchedule.DurationCountInYears = 2

New-AzRecoveryServicesBackupProtectionPolicy -Name "Tokyo-mssql-policy" -WorkloadType MSSQL -BackupManagementType AzureWorkload -RetentionPolicy $retentionPolicy -SchedulePolicy $schedulePolicy -VaultId $vault.ID

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:

  • AzureVM
  • AzureStorage
  • AzureWorkload

Parameter properties

Type:

Nullable<T>[BackupManagementType]

Default value:None
Accepted values:AzureVM, AzureStorage, AzureWorkload
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:3
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-BackupSnapshotResourceGroup

Custom resource group name to store the instant recovery points of managed virtual machines. This is optional

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-BackupSnapshotResourceGroupSuffix

Custom resource group name suffix to store the instant recovery points of managed virtual machines. This is optional

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-Confirm

Prompts you for confirmation before running the cmdlet.

Parameter properties

Type:SwitchParameter
Default value:None
Supports wildcards:False
DontShow:False
Aliases:cf

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-DefaultProfile

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

Parameter properties

Type:IAzureContextContainer
Default value:None
Supports wildcards:False
DontShow:False
Aliases:AzContext, AzureRmContext, AzureCredential

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-MoveToArchiveTier

Specifies whether recovery points should be moved to archive storage by the policy or not. Allowed values are $true, $false

Parameter properties

Type:

Nullable<T>[Boolean]

Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:6
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-Name

Specifies the name of the policy.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:1
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-RetentionPolicy

Specifies the base RetentionPolicy object. You can use the Get-AzRecoveryServicesBackupRetentionPolicyObject cmdlet to get a RetentionPolicy object.

Parameter properties

Type:RetentionPolicyBase
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:4
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-SchedulePolicy

Specifies the base SchedulePolicy object. You can use the Get-AzRecoveryServicesBackupSchedulePolicyObject cmdlet to get a SchedulePolicy object.

Parameter properties

Type:SchedulePolicyBase
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:5
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-SnapshotConsistencyType

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

Parameter properties

Type:SnapshotConsistencyType
Default value:None
Accepted values:Default, OnlyCrashConsistent
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-TierAfterDuration

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

Parameter properties

Type:

Nullable<T>[Int32]

Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:8
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-TierAfterDurationType

Specifies whether the TierAfterDuration is in Days or Months

Parameter properties

Type:String
Default value:None
Accepted values:Days, Months
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:9
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-TieringMode

Specifies whether to move recommended or all eligible recovery points to archive

Parameter properties

Type:TieringMode
Default value:None
Accepted values:TierRecommended, TierAllEligible
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:7
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-VaultId

ARM ID of the Recovery Services Vault.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:True
Value from pipeline by property name:False
Value from remaining arguments:False

-WhatIf

Shows what would happen if the cmdlet runs.

Parameter properties

Type:SwitchParameter
Default value:None
Supports wildcards:False
DontShow:False
Aliases:wi

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-WorkloadType

Workload type of the resource. The acceptable values for this parameter are:

  • AzureVM
  • AzureFiles
  • MSSQL

Parameter properties

Type:WorkloadType
Default value:None
Accepted values:AzureVM, AzureFiles, MSSQL
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:2
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

CommonParameters

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.

Inputs

WorkloadType

Nullable<T>

RetentionPolicyBase

SchedulePolicyBase

String

Outputs

PolicyBase