你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

使用 REST API 创建 Azure 恢复服务备份策略

本文介绍如何为备份 Azure VM、Azure VM 中的 SQL 数据库、Azure VM 中的 SAP HANA 数据库和 Azure 文件共享创建策略。

详细了解如何使用 REST API 为 Azure 恢复服务保管库创建或修改备份策略

创建或更新策略

要创建或更新 Azure 备份策略,请使用以下 PUT 操作。

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

{policyName}{vaultName} 在 URI 中提供。 其他信息在请求正文中提供。

创建请求正文

要为 Azure VM 备份创建策略,请求正文需要具有以下组件:

名称 必需 类型​​ 说明
properties True ProtectionPolicy:AzureIaaSVMProtectionPolicy ProtectionPolicyResource 属性
tags Object 资源标记

有关请求正文中定义的完整列表,请参阅备份策略 REST API 文章

示例请求正文

本部分提供了示例请求正文,用于为 Azure VM、Azure VM 中的 SQL 数据库、Azure VM 中的 SAP HANA 数据库和 Azure 文件共享的备份创建策略。

选择数据源

以下请求正文定义了 Azure VM 备份的标准备份策略。

此策略:

  • 在每个星期一、星期三、星期四上午 10:00(太平洋标准时间)创建每周备份。
  • 将每个星期一、星期三、星期四创建的备份保留一周。
  • 将每个月的第一个星期三和第三个星期四创建的备份保留两个月(取代以前的保留条件,如果有)。
  • 将 2 月和 11 月的第四个星期一和第四个星期四创建的备份保留四年(取代以前的保留条件,如果有)。
{
  "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"
        }
      }
    }
  }
}

以下请求正文为一天创建多个备份的 Azure VM 备份定义了增强的备份策略。

此策略:

  • 从每天下午 3:30 UTC 开始,每 4 小时执行一次备份
  • 将即时恢复快照保留 7 天
  • 将每日备份保留 180 天
  • 将每周星期日进行的备份保留 12 周
  • 将每月第一个星期日进行的备份保留 12 个月
{
	"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
	}
}

重要

计划和保留期的时间格式仅支持日期时间, 不支持单独的时间格式。

响应

创建/更新备份策略是一项异步操作。 这意味着,此操作会创建另一个需要单独跟踪的操作。

它返回两个响应:创建另一个操作时返回“202 (已接受)”。 然后,在该操作完成时显示“200 (正常)”。

名称 Type 说明
200 正常 Protection PolicyResource OK
202 已接受 已接受

示例响应

提交创建或更新策略的 PUT 请求后,初始响应为 202 (Accepted),以及 location 标头或 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

然后通过简单的 GET 命令并使用 location 标头或 Azure-AsyncOperation 标头跟踪生成的操作 。

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

操作完成后,它将在响应正文中返回 200 (OK) 和策略内容。

{
  "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
  }
}

如果已使用某个策略来保护某个项,对该策略进行任何更新都会导致修改所有此类关联项的保护。

后续步骤

为不受保护的 Azure VM 启用保护

有关 Azure 备份 REST API 的详细信息,请参阅以下文档: