Επεξεργασία

Κοινή χρήση μέσω


Create Azure Recovery Services backup policies by using REST API

This article describes how to create policies for the backup of Azure VM, SQL database in Azure VM, SAP HANA database in Azure VM, and Azure File share.

Learn more about creating or modifying a backup policy for an Azure Recovery Services vault by using REST API.

Create or update a policy

To create or update an Azure Backup policy, use the following PUT operation.

PUT https://management.azure.com/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupPolicies/{policyName}?api-version=2019-05-13

The {policyName} and {vaultName} are provided in the URI. Additional information is provided in the request body.

Create the request body

If you want to create a policy for Azure VM backup, the request body needs to have the following components:

Name Required Type Description
properties True ProtectionPolicy:AzureIaaSVMProtectionPolicy ProtectionPolicyResource properties
tags Object Resource tags

For the complete list of definitions in the request body, see the backup policy REST API article.

Example request body

This section provides the example request body to create policies for the backup of Azure VM, SQL database in Azure VM, SAP HANA database in Azure VM, and Azure File share.

Choose a datasource:

The following request body defines a standard backup policy for Azure VM backups.

This policy:

  • Takes a weekly backup every Monday, Wednesday, Thursday at 10:00 AM Pacific Standard Time.
  • Retains the backups taken on every Monday, Wednesday, Thursday for one week.
  • Retains the backups taken on every first Wednesday and third Thursday of a month for two months (overrides the previous retention conditions, if any).
  • Retains the backups taken on fourth Monday and fourth Thursday in February and November for four years (overrides the previous retention conditions, if any).
{
  "properties": {
    "backupManagementType": "AzureIaasVM",
    "timeZone": "Pacific Standard Time",
    "schedulePolicy": {
      "schedulePolicyType": "SimpleSchedulePolicy",
      "scheduleRunFrequency": "Weekly",
      "scheduleRunTimes": [
        "2018-01-24T10:00:00Z"
      ],
      "scheduleRunDays": [
        "Monday",
        "Wednesday",
        "Thursday"
      ]
    },
    "retentionPolicy": {
      "retentionPolicyType": "LongTermRetentionPolicy",
      "weeklySchedule": {
        "daysOfTheWeek": [
          "Monday",
          "Wednesday",
          "Thursday"
        ],
        "retentionTimes": [
          "2018-01-24T10:00:00Z"
        ],
        "retentionDuration": {
          "count": 1,
          "durationType": "Weeks"
        }
      },
      "monthlySchedule": {
        "retentionScheduleFormatType": "Weekly",
        "retentionScheduleWeekly": {
          "daysOfTheWeek": [
            "Wednesday",
            "Thursday"
          ],
          "weeksOfTheMonth": [
            "First",
            "Third"
          ]
        },
        "retentionTimes": [
          "2018-01-24T10:00:00Z"
        ],
        "retentionDuration": {
          "count": 2,
          "durationType": "Months"
        }
      },
      "yearlySchedule": {
        "retentionScheduleFormatType": "Weekly",
        "monthsOfYear": [
          "February",
          "November"
        ],
        "retentionScheduleWeekly": {
          "daysOfTheWeek": [
            "Monday",
            "Thursday"
          ],
          "weeksOfTheMonth": [
            "Fourth"
          ]
        },
        "retentionTimes": [
          "2018-01-24T10:00:00Z"
        ],
        "retentionDuration": {
          "count": 4,
          "durationType": "Years"
        }
      }
    }
  }
}

The following request body defines an enhanced backup policy for Azure VM backups creating multiple backups a day.

This policy:

  • Takes a backup every 4 hours from 3:30 PM UTC everyday
  • Retains instant recovery snapshot for 7 days
  • Retains the daily backups for 180 days
  • Retains the backups taken on the Sunday of every week for 12 weeks
  • Retains the backups taken on the first Sunday of every month for 12 months
{
	"properties": {
		"backupManagementType": "AzureIaasVM",
		"policyType": "V2",
		"instantRPDetails": {},
		"schedulePolicy": {
			"schedulePolicyType": "SimpleSchedulePolicyV2",
			"scheduleRunFrequency": "Hourly",
			"hourlySchedule": {
				"interval": 4,
				"scheduleWindowStartTime": "2023-02-06T15:30:00Z",
				"scheduleWindowDuration": 24
			}
		},
		"retentionPolicy": {
			"retentionPolicyType": "LongTermRetentionPolicy",
			"dailySchedule": {
				"retentionTimes": [
					"2023-02-06T15:30:00Z"
				],
				"retentionDuration": {
					"count": 180,
					"durationType": "Days"
				}
			},
			"weeklySchedule": {
				"daysOfTheWeek": [
					"Sunday"
				],
				"retentionTimes": [
					"2023-02-06T15:30:00Z"
				],
				"retentionDuration": {
					"count": 12,
					"durationType": "Weeks"
				}
			},
			"monthlySchedule": {
				"retentionScheduleFormatType": "Weekly",
				"retentionScheduleWeekly": {
					"daysOfTheWeek": [
						"Sunday"
					],
					"weeksOfTheMonth": [
						"First"
					]
				},
				"retentionTimes": [
					"2023-02-06T15:30:00Z"
				],
				"retentionDuration": {
					"count": 12,
					"durationType": "Months"
				}
			}
		},
		"tieringPolicy": {
			"ArchivedRP": {
				"tieringMode": "DoNotTier",
				"duration": 0,
				"durationType": "Invalid"
			}
		},
		"instantRpRetentionRangeInDays": 7,
		"timeZone": "UTC",
		"protectedItemsCount": 0
	}
}

Important

The time formats for schedule and retention support only DateTime. They don't support Time format alone.

Responses

The backup policy creation/update is a asynchronous operation. It means this operation creates another operation that needs to be tracked separately.

It returns two responses: 202 (Accepted) when another operation is created. Then 200 (OK) when that operation completes.

Name Type Description
200 OK Protection PolicyResource OK
202 Accepted Accepted

Example responses

Once you submit the PUT request for policy creation or updating, the initial response is 202 (Accepted) with a location header or Azure-async-header.

HTTP/1.1 202 Accepted
Pragma: no-cache
Retry-After: 60
Azure-AsyncOperation: https://management.azure.com/Subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/testVault/backupPolicies/testPolicy1/operations/00000000-0000-0000-0000-000000000000?api-version=2016-06-01
X-Content-Type-Options: nosniff
x-ms-request-id: db785be0-bb20-4598-bc9f-70c9428b170b
x-ms-client-request-id: e1f94eef-9b2d-45c4-85b8-151e12b07d03; e1f94eef-9b2d-45c4-85b8-151e12b07d03
Strict-Transport-Security: max-age=31536000; includeSubDomains
x-ms-ratelimit-remaining-subscription-writes: 1199
x-ms-correlation-request-id: db785be0-bb20-4598-bc9f-70c9428b170b
x-ms-routing-request-id: SOUTHINDIA:20180521T073907Z:db785be0-bb20-4598-bc9f-70c9428b170b
Cache-Control: no-cache
Date: Mon, 21 May 2018 07:39:06 GMT
Location: https://management.azure.com/Subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/testVault/backupPolicies/testPolicy1/operationResults/00000000-0000-0000-0000-000000000000?api-version=2019-05-13
X-Powered-By: ASP.NET

Then track the resulting operation using the location header or Azure-AsyncOperation header with a simple GET command.

GET https://management.azure.com/Subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/testVault/backupPolicies/testPolicy1/operationResults/00000000-0000-0000-0000-000000000000?api-version=2019-05-13

Once the operation completes, it returns 200 (OK) with the policy content in the response body.

{
  "id": "/Subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/testVault/backupPolicies/testPolicy1",
  "name": "testPolicy1",
  "type": "Microsoft.RecoveryServices/vaults/backupPolicies",
  "properties": {
    "backupManagementType": "AzureIaasVM",
    "schedulePolicy": {
      "schedulePolicyType": "SimpleSchedulePolicy",
      "scheduleRunFrequency": "Weekly",
      "scheduleRunDays": [
        "Monday",
        "Wednesday",
        "Thursday"
      ],
      "scheduleRunTimes": [
        "2018-01-24T10:00:00Z"
      ],
      "scheduleWeeklyFrequency": 0
    },
    "retentionPolicy": {
      "retentionPolicyType": "LongTermRetentionPolicy",
      "weeklySchedule": {
        "daysOfTheWeek": [
          "Monday",
          "Wednesday",
          "Thursday"
        ],
        "retentionTimes": [
          "2018-01-24T10:00:00Z"
        ],
        "retentionDuration": {
          "count": 1,
          "durationType": "Weeks"
        }
      },
      "monthlySchedule": {
        "retentionScheduleFormatType": "Weekly",
        "retentionScheduleWeekly": {
          "daysOfTheWeek": [
            "Wednesday",
            "Thursday"
          ],
          "weeksOfTheMonth": [
            "First",
            "Third"
          ]
        },
        "retentionTimes": [
          "2018-01-24T10:00:00Z"
        ],
        "retentionDuration": {
          "count": 2,
          "durationType": "Months"
        }
      },
      "yearlySchedule": {
        "retentionScheduleFormatType": "Weekly",
        "monthsOfYear": [
          "February",
          "November"
        ],
        "retentionScheduleWeekly": {
          "daysOfTheWeek": [
            "Monday",
            "Thursday"
          ],
          "weeksOfTheMonth": [
            "Fourth"
          ]
        },
        "retentionTimes": [
          "2018-01-24T10:00:00Z"
        ],
        "retentionDuration": {
          "count": 4,
          "durationType": "Years"
        }
      }
    },
    "timeZone": "Pacific Standard Time",
    "protectedItemsCount": 0
  }
}

If a policy is already being used to protect an item, any update in the policy will result in modifying protection for all such associated items.

Next steps

Enable protection for an unprotected Azure VM.

For more information on the Azure Backup REST APIs, see the following documents: