(Azure)如何在Recoveryservices保管库中更改每个策略的保留期限

时间:2018-07-22 08:38:20

标签: powershell azure azure-backup-vault

需要帮助更改Recovery Services保管库中每个备份策略的保留期限。我们有多个保管库,每个保管库中有许多策略。因此需要编写该过程的脚本。

下面是我用来获取所有保管库中所有策略的脚本。但是无法更改每个策略的保留期

$recoveryServicesVaults=Get-AzureRmRecoveryServicesVault
foreach($recoveryServicesVault in $recoveryServicesVaults)
{
 Set-AzureRmRecoveryServicesVaultContext -Vault $recoveryServicesVault
 $backupPolicies=Get-AzureRmRecoveryServicesBackupProtectionPolicy - 
 WarningAction Ignore
 $backupPolicyArray=@()
 foreach($backupPolicy in $backupPolicies)
 {
 $Info = New-Object PSObject -Property @{
 PolicyName=$backupPolicy.Name
 WorkloadType=$backupPolicy.WorkloadType
 DailyRetentionPolicyDuration=$backupPolicy.RetentionPolicy.dailyschedule.DurationCountInDays
  }
  $backupPolicyArray += $Info
  }
 $backupPolicyArray
   }

1 个答案:

答案 0 :(得分:0)

您需要先创建一个保留策略,然后使用新的保留策略更新备份策略。使用Set-AzureRmRecoveryServicesBackupProtectionPolicy cmdlet更新策略。 请参阅以下示例以更新策略。您可以提供是否要启用或禁用每日,每周,每月或每年的计划,还可以提供每种类型的计划持续时间。这取决于您的要求。

$ recoveryServicesVaults = Get-AzureRmRecoveryServicesVault

foreach($ recoveryServicesVaults中的$ recoveryServicesVault)

{

 Set-AzureRmRecoveryServicesVaultContext -Vault $recoveryServicesVault

 $backupPolicies=Get-AzureRmRecoveryServicesBackupProtectionPolicy -WarningAction Ignore

 foreach($backupPolicy in $backupPolicies)
 {
     $schPol = Get-AzureRmRecoveryServicesBackupSchedulePolicyObject -WorkloadType "AzureVM"
     $retPol = Get-AzureRmRecoveryServicesBackupRetentionPolicyObject -WorkloadType "AzureVM"

     $retPol.IsWeeklyScheduleEnabled  = $true
     $retPol.IsMonthlyScheduleEnabled = $true
     $retPol.IsYearlyScheduleEnabled =  $true
     $retPol.DailySchedule.DurationCountInDays = 90
     $retpol.WeeklySchedule.DurationCountInWeeks = 10
     $retpol.MonthlySchedule.DurationCountInMonths = 4
     $retpol.YearlySchedule.DurationCountInYears = 1
     Set-AzureRmRecoveryServicesBackupProtectionPolicy -Policy $backupPolicy -SchedulePolicy $SchPol -RetentionPolicy $RetPol
  }

}