使用 CLI 更新现有 VM 备份策略Update the existing VM backup policy using CLI

可以使用 Azure CLI 来更新现有的 VM 备份策略。You can use Azure CLI to update an existing VM backup policy. 本文将介绍如何将现有策略导出到 JSON 文件、如何修改该文件,以及如何通过 Azure CLI 来使用修改后的策略更新策略。This article will explain how to export the existing policy to a JSON file, modify the file, and then use Azure CLI to update the policy with the modified policy.

修改现有策略Modify an existing policy

若要修改现有 VM 备份策略,请执行以下步骤:To modify an existing VM backup policy, follow these steps:

  1. 执行 az backup policy show 命令,以检索要更新的策略的详细信息。Execute the az backup policy show command to retrieve the details of policy you want to update.

    例如:Example:

    az backup policy show --name testing123 --resource-group rg1234 --vault-name testvault
    

    上面的示例显示了名为 testing123 的 VM 策略的详细信息。The example above shows the details for a VM policy with the name testing123.

    输出:Output:

    {
    "eTag": null,
    "id": "/Subscriptions/efgsf-123-test-subscription/resourceGroups/rg1234/providers/Microsoft.RecoveryServices/vaults/testvault/backupPolicies/testing123",
    "location": null,
    "name": "testing123",
    "properties": {
        "backupManagementType": "AzureIaasVM",
        "instantRpDetails": {
        "azureBackupRgNamePrefix": null,
        "azureBackupRgNameSuffix": null
        },
        "instantRpRetentionRangeInDays": 2,
        "protectedItemsCount": 0,
        "retentionPolicy": {
        "dailySchedule": {
            "retentionDuration": {
            "count": 180,
            "durationType": "Days"
            },
            "retentionTimes": [
            "2020-08-03T04:30:00+00:00"
            ]
        },
        "monthlySchedule": null,
        "retentionPolicyType": "LongTermRetentionPolicy",
        "weeklySchedule": {
            "daysOfTheWeek": [
            "Sunday"
            ],
            "retentionDuration": {
            "count": 30,
            "durationType": "Weeks"
            },
            "retentionTimes": [
            "2020-08-03T04:30:00+00:00"
            ]
        },
        "yearlySchedule": null
        },
        "schedulePolicy": {
        "schedulePolicyType": "SimpleSchedulePolicy",
        "scheduleRunDays": null,
        "scheduleRunFrequency": "Daily",
        "scheduleRunTimes": [
            "2020-08-03T04:30:00+00:00"
        ],
        "scheduleWeeklyFrequency": 0
        },
        "timeZone": "UTC"
    },
    "resourceGroup": "azurefiles",
    "tags": null,
    "type": "Microsoft.RecoveryServices/vaults/backupPolicies"
    }
    
  2. 将上面的输出保存到一个 json 文件中。Save the above output in a .json file. 例如,让我们将其保存为 Policy.json。For example, let's save it as Policy.json.

  3. 根据需要更新该 JSON 文件,并保存所做的更改。Update the JSON file based on your requirements and save the changes.

    示例:若要将“每周保留”更新为 60 天,请将此计数更改为60,以更新 JSON 文件的以下部分。Example: To update the weekly retention to 60 days, update the following section of the JSON file by changing the count to 60.

            "retentionDuration": {
          "count": 60,
          "durationType": "Weeks"
        }
    
    
  4. 保存更改。Save the changes.

  5. 执行 az backup policy set 命令,并将更新后的 JSON 文件的完整路径作为 --policy 参数的值传递。Execute the az backup policy set command and pass the complete path of the updated JSON file as the value for the - - policy parameter.

    az backup policy set --resource-group rg1234 --vault-name testvault --policy C:\temp2\Policy.json --name testing123
    

备注

还可以通过执行 az backup policy get-default-for-vm 命令来检索示例 JSON 策略。You can also retrieve the sample JSON policy by executing the az backup policy get-default-for-vm command.

后续步骤Next steps