共用方式為


使用 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 備份的原則,要求本文必須具有下列元件:

名稱 必要 類型​ 描述
內容 True ProtectionPolicy:AzureIaaSVMProtectionPolicy ProtectionPolicyResource 屬性
標記 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
	}
}

重要

排程和保留期的時間格式僅支援 DateTime。 不支援單獨的 Time 格式。

回覆

備份原則的建立/更新為非同步作業。 這表示此作業會建立另一項需要個別追蹤的作業。

其會傳回兩個回應:在建立另一項作業時傳回 202 (已接受)。 然後,在該作業完成時傳回 200 (確定)。

名稱 類型​​ 描述
200 OK 保護 PolicyResource 確定
202 已接受 已接受

範例回應

一旦提交 PUT 要求以供建立或更新原則,初始回應為 202 (已接受) 以及位置標頭或 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

然後,使用位置標頭或 Azure-AsyncOperation 標頭搭配簡單的 GET 命令,來追蹤所產生的作業。

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 (確定) 以及原則內容。

{
  "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 虛擬機器啟用保護

如需 Azure 備份 REST API 的詳細資訊,請參閱下列文件: