如何使用CLI创建Azure备份策略?

时间:2019-07-09 03:17:00

标签: azure azure-cli

1 个答案:

答案 0 :(得分:2)

实际上它支持,但是官方文档缺少说明,REST API表示createupdate使用相同的api。

enter image description here

您可以尝试以下命令,它对我而言效果很好。

az backup policy set --policy '{
  "name": "testpolicy3",
  "properties": {
    "backupManagementType": "AzureIaasVM",
    "instantRpRetentionRangeInDays": 2,
    "protectedItemsCount": 0,
    "retentionPolicy": {
      "dailySchedule": {
        "retentionDuration": {
          "count": 180,
          "durationType": "Days"
        },
        "retentionTimes": [
          "2019-07-09T07:30:00+00:00"
        ]
      },
      "monthlySchedule": {
        "retentionDuration": {
          "count": 60,
          "durationType": "Months"
        },
        "retentionScheduleDaily": null,
        "retentionScheduleFormatType": "Weekly",
        "retentionScheduleWeekly": {
          "daysOfTheWeek": [
            "Sunday"
          ],
          "weeksOfTheMonth": [
            "First"
          ]
        },
        "retentionTimes": [
          "2019-07-09T07:30:00+00:00"
        ]
      },
      "retentionPolicyType": "LongTermRetentionPolicy",
      "weeklySchedule": {
        "daysOfTheWeek": [
          "Sunday"
        ],
        "retentionDuration": {
          "count": 12,
          "durationType": "Weeks"
        },
        "retentionTimes": [
          "2019-07-09T07:30:00+00:00"
        ]
      },
      "yearlySchedule": {
        "monthsOfYear": [
          "January"
        ],
        "retentionDuration": {
          "count": 10,
          "durationType": "Years"
        },
        "retentionScheduleDaily": null,
        "retentionScheduleFormatType": "Weekly",
        "retentionScheduleWeekly": {
          "daysOfTheWeek": [
            "Sunday"
          ],
          "weeksOfTheMonth": [
            "First"
          ]
        },
        "retentionTimes": [
          "2019-07-09T07:30:00+00:00"
        ]
      }
    },
    "schedulePolicy": {
      "schedulePolicyType": "SimpleSchedulePolicy",
      "scheduleRunDays": null,
      "scheduleRunFrequency": "Daily",
      "scheduleRunTimes": [
        "2019-07-09T07:30:00+00:00"
      ],
      "scheduleWeeklyFrequency": 0
    },
    "timeZone": "UTC"
  },
  "resourceGroup": "joywebapp",
  "tags": null,
  "type": "Microsoft.RecoveryServices/vaults/backupPolicies"
}' --resource-group 'joywebapp' --vault-name 'joyvault' 

enter image description here