Search code examples
azurecommand-line-interfacebackup

az backup policy create with custom yearly policy json


I am trying to create an AZURE BACKUP POLICY for a single annual backup with the following policy created by me:

{
  "properties": {
    "backupManagementType": "AzureIaasVM",
    "schedulePolicy": {
      "schedulePolicyType": "SimpleSchedulePolicy",
      "scheduleRunFrequency": "Weekly",
      "scheduleRunTimes": [
        "2018-01-24T10:00:00Z"
      ]
    },
    "retentionPolicy": {
      "retentionPolicyType": "LongTermRetentionPolicy",
      "yearlySchedule": {
        "retentionScheduleFormatType": "Weekly",
        "monthsOfYear": [
          "February"
        ],
        "retentionScheduleWeekly": {
          "daysOfTheWeek": [
            "Monday"
          ],
          "weeksOfTheMonth": [
            "Fourth"
          ]
        },
        "retentionTimes": [
          "2018-01-24T10:00:00Z"
        ],
        "retentionDuration": {
          "count": 1,
          "durationType": "Years"
        }
      }
    }
  }
}

Using the following command via CLI:

az backup policy create \
 --backup-management-type AzureIaasVM \
                        --policy _POCBKP/policy-test.json \
                        --name SimpleRetentionPolicy \
                        --resource-group $(RESOURCE_GROUP) \
                        --vault-name $(RESOURCE_GROUP)-Backup-Vault

I am trying in various ways and with the documentation but I am not understanding something correctly.

The output:

2022-03-17T12:35:18.4460214Z ERROR: (BMSUserErrorInvalidPolicyInput) Input for create or update policy is not in proper format. Please check format of parameters like schedule time, schedule days, retention time and retention days 
2022-03-17T12:35:18.4461562Z Code: BMSUserErrorInvalidPolicyInput
2022-03-17T12:35:18.4462379Z Message: Input for create or update policy is not in proper format. Please check format of parameters like schedule time, schedule days, retention time and retention days 

Solution

  • @RCat In your policy, you have set the backup schedule to weekly, however the weekly retention schedule is not set. Here is sample policy for your reference.

    {
        "properties": {
        "backupManagementType": "AzureIaasVM",
        "schedulePolicy": {
          "schedulePolicyType": "SimpleSchedulePolicy",
          "scheduleRunFrequency": "Weekly",
          "scheduleRunDays": [
            "Monday"
          ],
          "scheduleRunTimes": [
            "2018-01-24T10:00:00Z"
          ],
          "scheduleWeeklyFrequency": 0
        },
        "retentionPolicy": {
          "retentionPolicyType": "LongTermRetentionPolicy",
          "weeklySchedule": {
            "daysOfTheWeek": [
              "Monday"
            ],
            "retentionTimes": [
              "2018-01-24T10:00:00Z"
            ],
            "retentionDuration": {
              "count": 1,
              "durationType": "Weeks"
            }
          },
          "yearlySchedule": {
            "retentionScheduleFormatType": "Weekly",
            "monthsOfYear": [
              "February"
            ],
            "retentionScheduleWeekly": {
              "daysOfTheWeek": [
                "Monday"
              ],
              "weeksOfTheMonth": [
                "Fourth"
              ]
            },
            "retentionTimes": [
              "2018-01-24T10:00:00Z"
            ],
            "retentionDuration": {
              "count": 4,
              "durationType": "Years"
            }
          }
        },
        "timeZone": "Pacific Standard Time",
        "protectedItemsCount": 0
      }
    }