Upravit

Sdílet prostřednictvím


New-AzRecoveryServicesBackupProtectionPolicy

Creates a Backup protection policy.

Syntax

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
Type:Nullable<T>[BackupManagementType]
Accepted values:AzureVM, AzureStorage, AzureWorkload
Position:3
Default value:None
Required:False
Accept pipeline input:True
Accept wildcard characters:False

-BackupSnapshotResourceGroup

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

Type:String
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-BackupSnapshotResourceGroupSuffix

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

Type:String
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Confirm

Prompts you for confirmation before running the cmdlet.

Type:SwitchParameter
Aliases:cf
Position:Named
Default value:None
Required:False
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
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-MoveToArchiveTier

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

Type:Nullable<T>[Boolean]
Position:6
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Name

Specifies the name of the policy.

Type:String
Position:1
Default value:None
Required:True
Accept pipeline input:False
Accept wildcard characters:False

-RetentionPolicy

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

Type:RetentionPolicyBase
Position:4
Default value:None
Required:False
Accept pipeline input:True
Accept wildcard characters:False

-SchedulePolicy

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

Type:SchedulePolicyBase
Position:5
Default value:None
Required:False
Accept pipeline input:True
Accept wildcard characters: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

Type:SnapshotConsistencyType
Accepted values:Default, OnlyCrashConsistent
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters: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

Type:Nullable<T>[Int32]
Position:8
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-TierAfterDurationType

Specifies whether the TierAfterDuration is in Days or Months

Type:String
Accepted values:Days, Months
Position:9
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-TieringMode

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

Type:TieringMode
Accepted values:TierRecommended, TierAllEligible
Position:7
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-VaultId

ARM ID of the Recovery Services Vault.

Type:String
Position:Named
Default value:None
Required:False
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
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-WorkloadType

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
Required:True
Accept pipeline input:True
Accept wildcard characters:False

Inputs

WorkloadType

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]]

RetentionPolicyBase

SchedulePolicyBase

String

Outputs

PolicyBase