简体   繁体   中英

How to create azure backup policy using CLI?

I can't find a way to create my custom backup policy via CLI https://docs.microsoft.com/en-us/cli/azure/backup/policy?view=azure-cli-latest

However, this can be done via REST API call https://docs.microsoft.com/en-us/azure/backup/backup-azure-arm-userestapi-createorupdatepolicy

Actually it supports, but the official doc is missing instructions, also the REST API indicates the create and update uses the same api.

在此处输入图片说明

You could try the command as below, it works fine on my side.

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' 

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM