0

需要帮助更改恢复服务保管库中每个备份策略的保留期。我们在每个保管库中有多个保管库和许多策略。因此想要编写该过程的脚本。

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

$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
   }
4

1 回答 1

0

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

$recoveryServicesVaults = 获取 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
  }

}

于 2018-07-23T14:12:49.280 回答