你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
本文解释了如何通过使用 RcEST API 从 Azure 备份 创建的还原点还原 Azure VM 上的 SQL Server 数据库。
完成本文的学习后,你将了解如何使用 REST API 执行以下操作:
- 查看已备份的 SQL 数据库的还原点。
- 查询 SQL 数据库和实例的快照恢复点和时间点恢复范围。
- 检索恢复点中包含的数据库和数据目录路径。
- 还原完整 SQL 数据库。
若要查看我们今天支持的备份和还原方案,请参阅 支持矩阵。 有关常见问题,请参阅 常见问题。
先决条件
我们假设你有一个用于还原的备份 SQL 数据库。 如果您还没有,请参阅使用 REST API 备份 Azure VM 中的 SQL Server 数据库以进行创建。
本文将使用以下资源:
- 恢复服务保管库:SQLServer2012
- 资源组:SQLServerSelfHost
- Sql Server:sqlserver-0
- SQL 数据库:msdb
主要区域还原
要在主区域启动常规还原作业,请参阅以下部分。 有关跨区域还原,请参阅 Cross-region-restore 部分。
获取 ContainerName 和 ProtectedItemName
对于大多数与还原相关的 API 调用,都需要传递 {containerName} 和 {protectedItemName} URI 参数的值。 使用 GET backupprotectableitems 操作的响应正文中的 ID 属性检索这些参数的值。 在我们的示例中,要保护的数据库的 ID 是:
/subscriptions/00000000-0000-0000-0000-0000000000/resourceGroups/SQLServerSelfHost/providers/microsoft.recoveryservices/vaults/SQLServer2012/backupFabrics/Azure/protectionContainers/VMAppContainer;Compute;SQLServerPMDemo;sqlserver-0/protectedItems/sqldatabase;mssqlserver;msdb
这些值转换为如下:
-
{containername}:VMAppContainer;Compute;SQLServerPMDemo;sqlserver-0 -
{protectedItemName}:sqldatabase;mssqlserver;msdb
获取已备份的 SQL 数据库的恢复点
还原任何备份的数据库:
选择恢复点以执行恢复操作。
可以使用恢复点列表 REST API 调用来列出备份项的可用恢复点。 这是一个使用所有相关值执行的 GET 操作。
GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupFabrics/{fabricName}/protectionContainers/{containerName}/protectedItems/{protectedItemName}/recoveryPoints?api-version=2016-12-01将 URI 值设置如下:
-
{fabricName}:Azure -
{vaultName}:SQLServer2012 -
{containerName}:VMAppContainer;Compute;SQLServerPMDemo;sqlserver-0 -
{protectedItemName}:sqldatabase;mssqlserver;msdb -
{resourceGroupName}:SQLServerSelfHost
GET URI 包含所有必需的参数。 无需额外的请求正文。
GET "https://management.azure.com/subscriptions/00000000-0000-0000-0000-0000000000/resourceGroups/SQLServerSelfHost/providers/microsoft.RecoveryServices/vaults/SQLServer2012/backupFabrics/Azure/protectionContainers/VMAppContainer;Compute;SQLServerPMDemo;sqlserver-0/protectedItems/sqldatabase;mssqlserver;msdb/recoveryPoints?api-version=2016-12-01"-
提取恢复点的示例响应
提交 GET URI 后,会返回 200 响应:
HTTP/1.1 200 OK
Pragma: no-cache
X-Content-Type-Options: nosniff
x-ms-request-id: fab6cc6f-db1e-4ac1-acac-fc82ebdb1fdb
x-ms-client-request-id: 6fb93717-2876-47df-b01f-d53af5f08785; 6fb93717-2876-47df-b01f-d53af5f08785
Strict-Transport-Security: max-age=31536000; includeSubDomains
x-ms-ratelimit-remaining-subscription-reads: 14999
x-ms-correlation-request-id: fab6cc6f-db1e-4ac1-acac-fc82ebdb1fdb
x-ms-routing-request-id: SOUTHINDIA:20180604T061127Z:fab6cc6f-db1e-4ac1-acac-fc82ebdb1fdb
Cache-Control: no-cache
Date: Mon, 04 Jun 2018 06:11:26 GMT
Server: Microsoft-IIS/8.0
X-Powered-By: ASP.NET
{
"value": [
{
"id": "/subscriptions/00000000-0000-0000-0000-0000000000/resourceGroups/SQLServerSelfHost/providers/microsoft.recoveryservices/vaults/SQLServer2012/backupFabrics/Azure/protectionContainers/VMAppContainer;Compute;SQLServerPMDemo;sqlserver-0/protectedItems/SQLDataBase;mssqlserver;msdb/recoveryPoints/55515936059579",
"name": "55515936059579",
"type": "Microsoft.RecoveryServices/vaults/backupFabrics/protectionContainers/protectedItems/recoveryPoints",
"properties": {
"objectType": "AzureWorkloadSQLRecoveryPoint",
"recoveryPointTimeInUTC": "2018-06-01T22:15:12Z",
"type": "Full"
}
},
{
"id": "/subscriptions/00000000-0000-0000-0000-0000000000/resourceGroups/SQLServerSelfHost/providers/microsoft.recoveryservices/vaults/SQLServer2012/backupFabrics/Azure/protectionContainers/VMAppContainer;Compute;SQLServerPMDemo;sqlserver-0/protectedItems/SQLDataBase;mssqlserver;msdb/recoveryPoints/62043109781074",
"name": "62043109781074",
"type": "Microsoft.RecoveryServices/vaults/backupFabrics/protectionContainers/protectedItems/recoveryPoints",
"properties": {
"objectType": "AzureWorkloadSQLRecoveryPoint",
"recoveryPointTimeInUTC": "2018-05-31T22:15:08Z",
"type": "Full"
}
},
{
"id": "/subscriptions/00000000-0000-0000-0000-0000000000/resourceGroups/SQLServerSelfHost/providers/microsoft.recoveryservices/vaults/SQLServer2012/backupFabrics/Azure/protectionContainers/VMAppContainer;Compute;SQLServerPMDemo;sqlserver-0/protectedItems/SQLDataBase;mssqlserver;msdb/recoveryPoints/69710749096214",
"name": "69710749096214",
"type": "Microsoft.RecoveryServices/vaults/backupFabrics/protectionContainers/protectedItems/recoveryPoints",
"properties": {
"objectType": "AzureWorkloadSQLRecoveryPoint",
"recoveryPointTimeInUTC": "2018-05-30T22:15:09Z",
"type": "Full"
}
},
{
"id": "/subscriptions/00000000-0000-0000-0000-0000000000/resourceGroups/SQLServerSelfHost/providers/microsoft.recoveryservices/vaults/SQLServer2012/backupFabrics/Azure/protectionContainers/VMAppContainer;Compute;SQLServerPMDemo;sqlserver-0/protectedItems/SQLDataBase;mssqlserver;msdb/recoveryPoints/55459165802209",
"name": "55459165802209",
"type": "Microsoft.RecoveryServices/vaults/backupFabrics/protectionContainers/protectedItems/recoveryPoints",
"properties": {
"objectType": "AzureWorkloadSQLRecoveryPoint",
"recoveryPointTimeInUTC": "2018-05-29T22:15:15Z",
"type": "Full"
}
},
{
"id": "/subscriptions/00000000-0000-0000-0000-0000000000/resourceGroups/SQLServerSelfHost/providers/microsoft.recoveryservices/vaults/SQLServer2012/backupFabrics/Azure/protectionContainers/VMAppContainer;Compute;SQLServerPMDemo;sqlserver-0/protectedItems/SQLDataBase;mssqlserver;msdb/recoveryPoints/56798287946753",
"name": "56798287946753",
"type": "Microsoft.RecoveryServices/vaults/backupFabrics/protectionContainers/protectedItems/recoveryPoints",
"properties": {
"objectType": "AzureWorkloadSQLRecoveryPoint",
"recoveryPointTimeInUTC": "2018-05-28T13:18:15Z",
"type": "Full"
}
},
{
"id": "/subscriptions/00000000-0000-0000-0000-0000000000/resourceGroups/SQLServerSelfHost/providers/microsoft.recoveryservices/vaults/SQLServer2012/backupFabrics/Azure/protectionContainers/VMAppContainer;Compute;SQLServerPMDemo;sqlserver-0/protectedItems/SQLDataBase;mssqlserver;msdb/recoveryPoints/DefaultRangeRecoveryPoint",
"name": "DefaultRangeRecoveryPoint",
"type": "Microsoft.RecoveryServices/vaults/backupFabrics/protectionContainers/protectedItems/recoveryPoints",
"properties": {
"objectType": "AzureWorkloadSQLPointInTimeRecoveryPoint",
"timeRanges": [
{
"startTime": "2018-05-28T11:03:34Z",
"endTime": "2018-06-02T00:02:31Z"
}
],
"type": "Log"
}
}
]
}
上述响应中的 {name} 字段标识了恢复点。
查询快照和流式恢复点
对于快照保护的SQL实例和数据库,以下恢复点查询使用API版本 2024-01-31-preview 。 用保险库详细信息以及通过 列出受保护项 命令返回的容器和受保护项名称替换 URI 占位符。 发送请求时对过滤表达式进行 URL 编码。
使用 restorePointQueryType 选择恢复点类型:
| Value | 返回的恢复点 |
|---|---|
FullDifferentialAndSnapshot |
数据库的完整恢复点、差分恢复点和快照恢复点。 |
Snapshot |
数据库或实例的快照恢复点。 |
FullAndDifferential |
数据库的完整和差分恢复点流式传输。 |
Log |
数据库的日志恢复时间范围。 |
列出完整、差分和快照恢复点
使用数据库保护的项目名称,例如 SQLDataBase;mssqlserver;testdb:
GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupFabrics/Azure/protectionContainers/{containerName}/protectedItems/{databaseProtectedItemName}/recoveryPoints?api-version=2024-01-31-preview&$filter=restorePointQueryType eq 'FullDifferentialAndSnapshot'
列出快照恢复点
对于数据库,使用其数据库受保护项名称:
GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupFabrics/Azure/protectionContainers/{containerName}/protectedItems/{databaseProtectedItemName}/recoveryPoints?api-version=2024-01-31-preview&$filter=restorePointQueryType eq 'Snapshot'
对于实例,请使用其实例受保护项名称,例如 SQLInstance;mssqlserver:
GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupFabrics/Azure/protectionContainers/{containerName}/protectedItems/{instanceProtectedItemName}/recoveryPoints?api-version=2024-01-31-preview&$filter=restorePointQueryType eq 'Snapshot'
列出流式完整恢复点和差异恢复点
你也可以指定时间窗口,并包含软删除的恢复点:
GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupFabrics/Azure/protectionContainers/{containerName}/protectedItems/{databaseProtectedItemName}/recoveryPoints?api-version=2024-01-31-preview&$filter=startDate eq '2024-02-15 05:12:12 PM' and endDate eq '2024-02-22 05:12:12 PM' and restorePointQueryType eq 'FullAndDifferential' and includeSoftDeletedRP eq 'true'
用你要求的时间窗口替换样本日期。 该value数组包含恢复点,其属性包括type、recoveryPointTierDetails和recoveryPointTimeInUTC。 保留信息可以出现在 recoveryPointProperties,包括 expiryTime、 ruleName和 isSoftDeleted。
查询用于时间点还原的日志恢复范围
要列出数据库的日志恢复范围,请使用以下请求:
GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupFabrics/Azure/protectionContainers/{containerName}/protectedItems/{databaseProtectedItemName}/recoveryPoints?api-version=2024-01-31-preview&$filter=restorePointQueryType eq 'Log'
回复中包含一项 DefaultRangeRecoveryPoint 内容。 以下示例展示了选定的响应字段:
{
"value": [
{
"name": "DefaultRangeRecoveryPoint",
"properties": {
"objectType": "AzureWorkloadSQLPointInTimeRecoveryPoint",
"timeRanges": [
{
"startTime": "2024-02-07T17:12:13.2853054Z",
"endTime": "2024-02-22T15:30:13Z"
}
],
"type": "Log"
}
}
]
}
在返回的范围内选择恢复时间。
按恢复模式查询数据库日志范围
对于基于流的恢复,请指定 recoveryMode eq 'WorkloadRecovery':
GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupFabrics/Azure/protectionContainers/{containerName}/protectedItems/{databaseProtectedItemName}/recoveryPoints?api-version=2024-01-31-preview&$filter=restorePointQueryType eq 'Log' and recoveryMode eq 'WorkloadRecovery'
对于基于快照的恢复,请指定 recoveryMode eq 'SnapshotAttachAndRecover':
GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupFabrics/Azure/protectionContainers/{containerName}/protectedItems/{databaseProtectedItemName}/recoveryPoints?api-version=2024-01-31-preview&$filter=restorePointQueryType eq 'Log' and recoveryMode eq 'SnapshotAttachAndRecover'
这两种查询都返回了之前显示的日志恢复范围响应格式。
查询数据库日志范围以进行实例恢复
对于实例时间点恢复,首先选择实例快照恢复点并 检索其包含的数据库。 对于每个包含的数据库,请用所选的基础快照详细信息查询其日志范围:
GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupFabrics/Azure/protectionContainers/{containerName}/protectedItems/{databaseProtectedItemName}/recoveryPoints?api-version=2024-01-31-preview&$filter=restorePointQueryType eq 'Log' and recoveryMode eq 'SnapshotAttachAndRecover' and baseSnapshotRPId eq '{baseSnapshotRPId}' and baseRPDatasourceId eq '{baseRPDatasourceId}'
-
{baseSnapshotRPId}:所选实例快照恢复点的name。 -
{baseRPDatasourceId}:实例受保护项的protectedItemDataSourceId,而不是子数据库的数据源 ID。 -
{databaseProtectedItemName}:被查询子数据库的受保护项名称。
在实例快照中获取数据库和磁盘路径
获取所选实例恢复点,以检索其包含的数据库和磁盘路径。 准备实例快照恢复或实例时间点恢复时,使用相同的元数据:
GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupFabrics/Azure/protectionContainers/{containerName}/protectedItems/{instanceProtectedItemName}/recoveryPoints/{snapshotRecoveryPointId}?api-version=2024-01-31-preview
{snapshotRecoveryPointId} 是恢复点的 name。 以下示例展示了选定的响应字段:
{
"name": "2265756871711897922",
"properties": {
"objectType": "AzureWorkloadSQLRecoveryPoint",
"extendedInfo": {
"dataDirectoryTimeInUTC": "2024-03-13T08:03:25Z",
"dataDirectoryPaths": [
{
"type": "DiskDrives",
"path": "F:\\"
},
{
"type": "DiskDrives",
"path": "G:\\"
}
],
"includedDatabases": [
{
"datasourceId": "2265838378698362078",
"datasourceName": "MSSQLSERVER;user1"
}
],
"snapshotRecoveryPointInfo": {}
},
"recoveryPointTimeInUTC": "2024-03-13T08:03:25Z",
"type": "SnapshotFull",
"recoveryPointTierDetails": [
{
"type": "InstantRP",
"status": "Valid"
}
]
}
}
extendedInfo.includedDatabases 标识所选快照中捕获的数据库。
extendedInfo.dataDirectoryPaths 显示可用于高级还原配置的磁盘路径。
获取数据库路径以进行高级还原配置
对于数据库流式或快照恢复点,请检索恢复点的详细信息:
GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupFabrics/Azure/protectionContainers/{containerName}/protectedItems/{databaseProtectedItemName}/recoveryPoints/{recoveryPointId}?api-version=2023-02-01
properties.extendedInfo.dataDirectoryPaths检查数据和日志文件路径及逻辑名称。 例如:
{
"dataDirectoryTimeInUTC": "2024-03-04T18:03:35Z",
"dataDirectoryPaths": [
{
"type": "Data",
"path": "F:\\DATA\\TestDB1.mdf",
"logicalName": "TestDB1"
},
{
"type": "Log",
"path": "F:\\LOG\\TestDB1_log.ldf",
"logicalName": "TestDB1_log"
}
],
"snapshotRecoveryPointInfo": {}
}
对于数据库时间点恢复,在列出日志恢复范围时请求扩展信息。 以下示例使用基于快照的恢复:
GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupFabrics/Azure/protectionContainers/{containerName}/protectedItems/{databaseProtectedItemName}/recoveryPoints?api-version=2023-02-01&$filter=startDate eq '2024-02-06 07:50:56 AM' and endDate eq '2024-03-07 07:23:05 AM' and extendedInfo eq 'true' and restorePointQueryType eq 'Log' and recoveryMode eq 'SnapshotAttachAndRecover'
用所需的查询时间范围替换样本日期。 响应包含日志恢复范围和 properties.extendedInfo,包括 dataDirectoryTimeInUTC、、 dataDirectoryPaths和 snapshotRecoveryPointInfo。
前述查询用于检索恢复点和恢复配置元数据。 以下部分介绍了现有的流式数据库恢复请求。
使用 REST API 的数据库恢复
触发器还原是一个 POST 请求。 若要执行此操作,请使用触发器还原 REST API。
POST https://management.azure.com/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupFabrics/{fabricName}/protectionContainers/{containerName}/protectedItems/{protectedItemName}/recoveryPoints/{recoveryPointId}/restore?api-version=2019-05-13
值 {containerName} 和 {protectedItemName} 的设置方式如此处,recoveryPointID 是前面所述的恢复点的 {name} 字段。
POST https://management.azure.com/Subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SQLServerSelfHost/providers/Microsoft.RecoveryServices/vaults/SQLServer2012/backupFabrics/Azure/protectionContainers/VMAppContainer;Compute;SQLServerPMDemo;sqlserver-0/protectedItems/sqldatabase;mssqlserver;msdb/recoveryPoints/56798287946753/restore?api-version=2019-05-13'
创建请求正文
将数据库还原到同一数据目录的请求正文示例
以下请求正文定义触发 SQL 数据库还原到同一数据目录所需的属性。
{
"properties":{
"objectType":"AzureWorkloadSQLRestoreRequest",
"shouldUseAlternateTargetLocation":false,
"isNonRecoverable":false,
"targetInfo":{"ContainerName": "compute;SQLServerPMDemo;sqlserver-0", "DatabaseName" : "SQLINSTANCE/msdb"},
"alternateDirectoryPaths":null,
"isFallbackOnDefaultDirectoryEnabled":true,
"recoveryType":"AlternateLocation",
"sourceResourceId":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SQLServerPMDemo/providers/Azure/virtualmachines/compute;SQLServerPMDemo;sqlserver-0"
}
}
将数据库还原到替换数据目录的请求正文示例
以下请求正文定义触发 SQL 数据库还原到同一数据目录所需的属性。
{
"properties":{
"objectType":"AzureWorkloadSQLRestoreRequest",
"shouldUseAlternateTargetLocation":true,
"isNonRecoverable":false,
"targetInfo":
{
"overwriteOption":"Overwrite","containerName":"compute;oneboxrg;oneboxvm","databaseName":"SQLINSTANCE/msdb"},
"alternateDirectoryPaths":[{"mappingType":"Log","sourcePath":"C:\\SQLfiles\\Default.ldf","targetPath":"C:\\SQLFiles\\Temp.ldf"}],
"recoveryType":"AlternateLocation",
"sourceResourceId":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SQLServerPMDemo/providers/Azure/virtualmachines/compute;SQLServerPMDemo;sqlserver-0"
}
}
}
响应
触发还原操作是一个异步操作。 此操作会创建另一个需要单独跟踪的操作。
它将返回两个响应:创建另一个操作时为 202(已接受),该操作完成时为 200(确定)。
响应示例
Status Code:
OK
Headers:
Pragma : no-cache
Cache-Control : no-cache
Server : Microsoft-IIS/10.0,Microsoft-IIS/10.0
X-Content-Type-Options : nosniff
x-ms-request-id : f17973f5-c788-482f-8aad-6bb50e647a2e
x-ms-client-request-id : b0356a0e-c68d-4ac2-a53f-4f546685146d,b0356a0e-c68d-4ac2-a53f-4f546685146d
X-Powered-By : ASP.NET
Strict-Transport-Security : max-age=31536000; includeSubDomains
x-ms-ratelimit-remaining-subscription-resource-requests: 149
x-ms-correlation-request-id : f17973f5-c788-482f-8aad-6bb50e647a2e
x-ms-routing-request-id : SOUTHINDIA:20210801T104711Z:f17973f5-c788-482f-8aad-6bb50e647a2e
Date : Sun, 01 Aug 2021 10:47:11 GMT
{
"id":"/Subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SQLServerSelfHost/providers/Microsoft.RecoveryServices/vaults/SQLServer2012/backupJobs/0bda1a53-73fa-427e-9a1c-72a2016adee3",
"name": "0bda1a53-73fa-427e-9a1c-72a2016adee3",
"type": "Microsoft.RecoveryServices/vaults/backupJobs",
"properties": {
"jobType": "AzureWorkloadJob",
"actionsInfo": [
1
],
"workloadType": "SQLDataBase",
"duration": "PT1.6543659S",
"extendedInfo": {
"tasksList": [
{
"taskId": "Transfer data from vault",
"status": "InProgress"
}
],
"propertyBag": {
"Job Type": "Recovery to the original database"
}
},
"isUserTriggered": true,
"entityFriendlyName": "msdb [sqlserver-0]",
"backupManagementType": "AzureWorkload",
"operation": "Restore",
"status": "InProgress",
"startTime": "2021-08-01T10:47:09.5865449Z",
"activityId": "b0356a0e-c68d-4ac2-a53f-4f546685146d"
}
}
跨区域还原
如果已启用跨区域还原,则恢复点也将复制到配对的次要区域。 然后,可以提取这些恢复点,并在配对区域内的某台计算机上触发还原过程。 与常规还原时一样,目标计算机应注册到次要区域中的目标保管库。 以下步骤介绍端到端过程:
提取已复制到次要区域的备份项。
对于以下示例,需要:
- 一个容器:VMAppContainer;Compute;SQLServerPMDemo;sqlserver-0
- 一个受保护的项:sqldatabase;mssqlserver;msdb) 用于需要还原的数据库(使用本文档前面提到的步骤)。
提取已复制到次要区域的恢复点(相异恢复点和/或日志)
选择已注册到配对次要区域中某个保管库的目标服务器。
触发到该服务器的还原,然后使用 JobId 跟踪还原操作。
注意
次要区域中可用的备份数据的 RPO 为 12 小时。 因此,打开 CRR 时,次要区域的 RPO 为 12 小时 + 日志频率持续时间(可以设置为至少 15 分钟)。
从次要区域中提取不同的恢复点
使用列表恢复点 API 提取次要区域数据库的可用恢复点列表。 在下面的示例中,应用了可选的筛选器来提取给定时间范围内的完整恢复点和差异恢复点。
GET "https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SQLServerSelfHost/providers/Microsoft.RecoveryServices/vaults/SQLServer2012/backupFabrics/Azure/protectionContainers/VMAppContainer;compute;SQLServerPMDemo;sqlserver-0/protectedItems/SQLDataBase;mssqlserver;msdb/recoveryPoints/?$filter=startDate eq'2021-07-25 08:41:32 AM' and endDate eq '2021-08-01 08:41:45 AM' and restorePointQueryType eq 'FullAndDifferential' and extendedInfo eq 'True'&api-version=2018-12-20"
提取恢复点的示例响应
Headers:
Pragma : no-cache
X-Content-Type-Options : nosniff
x-ms-request-id : 66b3fbb4-e38a-4a4b-98c7-56db66ab52e6
x-ms-client-request-id : 35eb7834-8b5c-4a2c-adda-eee2ed02eb08,35eb7834-8b5c-4a2c-adda-eee2ed02eb08
Strict-Transport-Security : max-age=31536000; includeSubDomains
x-ms-ratelimit-remaining-subscription-resource-requests: 149
x-ms-correlation-request-id : 66b3fbb4-e38a-4a4b-98c7-56db66ab52e6
x-ms-routing-request-id : SOUTHINDIA:20210801T102906Z:66b3fbb4-e38a-4a4b-98c7-56db66ab52e6
Cache-Control : no-cache
Date : Sun, 01 Aug 2021 10:29:06 GMT
Server : Microsoft-IIS/10.0
X-Powered-By : ASP.NET
Body:
{
"value": [
{
"id":
"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SQLServerSelfHost/providers/Microsoft.RecoveryServices/vaults/SQLServer2012/backupFabrics/Azure/protectionContainers/VMAppContainer;compute;SQLServerPMDemo;sqlserver-0/protectedItems/SQLDataBase;mssqlserver;msdb/RecoveryPoints/932604119111216382",
"name": "932604119111216382",
"type": "Microsoft.RecoveryServices/vaults/backupFabrics/protectionContainers/protectedItems/recoveryPoints",
"properties": {
"objectType": "AzureWorkloadSQLRecoveryPoint",
"recoveryPointTimeInUTC": "2021-07-31T16:33:48Z",
"type": "Full"
}
},
{
"id":
"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SQLServerSelfHost/providers/Microsoft.RecoveryServices/vaults/SQLServer2012/backupFabrics/Azure/protectionContainers/VMAppContainer;compute;SQLServerPMDemo;sqlserver-0/protectedItems/SQLDataBase;mssqlserver;msdb/RecoveryPoints/932599942005436803",
"name": "932599942005436803",
"type": "Microsoft.RecoveryServices/vaults/backupFabrics/protectionContainers/protectedItems/recoveryPoints",
"properties": {
"objectType": "AzureWorkloadSQLRecoveryPoint",
"recoveryPointTimeInUTC": "2021-07-30T16:33:49Z",
"type": "Full"
}
},
.....
上述响应中的 {name} 字段标识了恢复点。
获取访问令牌
若要执行跨区域还原,需要访问令牌才能在 Azure 备份服务之间正常通信。 若要获取访问令牌,请执行以下步骤:
使用 Microsoft Entra 属性 API 提取次要区域(在以下示例中为 westus)的 Microsoft Entra 属性。
GET https://management.azure.com/subscriptions/{subscriptionId}/providers/Microsoft.RecoveryServices/locations/westus/backupAadProperties?api-version=2018-12-20返回的响应采用以下格式:
{ "properties": { "tenantId": "00000000-0000-0000-0000-000000000000", "audience": "https://RecoveryServices/IaasCoord/aadmgmt/wus", "servicePrincipalObjectId": "00000000-0000-0000-0000-000000000000" } }使用获取访问令牌 API 获取访问令牌,以支持 Azure 备份服务之间的通信。
POST https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupFabrics/{fabricName}/protectionContainers/{containerName}/protectedItems/{protectedItemName}/recoveryPoints/{recoveryPointId}/accessToken?api-version=2018-12-20对于请求正文,粘贴上一步中 Microsoft Entra 属性 API 返回的响应内容。
返回的响应格式如下所示:
{ "protectableObjectUniqueName": "MSSQLSERVER/model", "protectableObjectFriendlyName": "msdb", "protectableObjectWorkloadType": "SQL", "protectableObjectProtectionState": "Protected", "protectableObjectContainerHostOsName": "sqlserver-0", "protectableObjectParentLogicalContainerName": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SQLServerPMDemo/providers/Microsoft.Compute/virtualMachines/sqlserver-0", "containerId": "0000000", "policyName": "HourlyLogBackup", "policyId": "00000000-0000-0000-0000-000000000000", "objectType": "WorkloadCrrAccessToken", "accessTokenString": "<access-token-string>", "subscriptionId": "00000000-0000-0000-0000-000000000000", "resourceGroupName": "SQLServerSelfHost", "resourceName": "SQLServer2012", "resourceId": "0000000000000000000", "protectionContainerId": 0000000, "recoveryPointId": "932603497994988273", "recoveryPointTime": "7/31/2021 4:33:17 PM", "containerName": "Compute;SQLServerPMDemo;sqlserver-0", "containerType": "VMAppContainer", "backupManagementType": "AzureWorkload", "datasourceType": "SQLDataBase", "datasourceName": "msdb", "datasourceId": "932350676859704517", "datasourceContainerName": "Compute;SQLServerPMDemo;sqlserver-0", "coordinatorServiceStampId": "00000000-0000-0000-0000-000000000000", "coordinatorServiceStampUri": "https://pod01-wbcm1.eus.backup.windowsazure.com", "protectionServiceStampId": "00000000-0000-0000-0000-000000000000", "protectionServiceStampUri": "https://pod01-prot1j-int.eus.backup.windowsazure.com", "rpOriginalSAOption": false, "rpIsManagedVirtualMachine": false, "bMSActiveRegion": "EastUS" }
将磁盘还原到次区域
使用跨区域还原触发器 API 将某个项还原到次要区域。
POST https://management.azure.com/subscriptions/{subscriptionId}/providers/Microsoft.RecoveryServices/locations/{azureRegion}/backupCrossRegionRestore?api-version=2018-12-20
请求正文应包含两个部分:
crossRegionRestoreAccessDetails:粘贴上一步中执行的“获取访问令牌 API”请求的响应的属性块,以填充请求正文的这一部分。
restoreRequest:若要填充请求正文的 restoreRequest 段,需要将数据库需要还原到的容器(注册到次要区域的保管库)的详细信息以及还原的数据库存储时应使用的名称一起传递给该保管库。 若要将完整备份还原到次要区域,请指定恢复类型为 AlternateLocation。
下面是将 VM 的磁盘还原到次要区域的示例请求正文:
{
"crossRegionRestoreAccessDetails": {
"protectableObjectUniqueName": "MSSQLSERVER/model",
"protectableObjectFriendlyName": "msdb",
"protectableObjectWorkloadType": "SQL",
"protectableObjectProtectionState": "Protected",
"protectableObjectContainerHostOsName": "sqlserver-0",
"protectableObjectParentLogicalContainerName": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SQLServerPMDemo/providers/Microsoft.Compute/virtualMachines/sqlserver-0",
"containerId": "0000000",
"policyName": "HourlyLogBackup",
"policyId": "00000000-0000-0000-0000-000000000000",
"objectType": "WorkloadCrrAccessToken",
"accessTokenString": "<access-token-string>",
"subscriptionId": "00000000-0000-0000-0000-000000000000",
"resourceGroupName": "SQLServerSelfHost",
"resourceName": "SQLServer2012",
"resourceId": "0000000000000000000",
"protectionContainerId": 0000000,
"recoveryPointId": "932603497994988273",
"recoveryPointTime": "7/31/2021 4:33:17 PM",
"containerName": "Compute;SQLServerPMDemo;sqlserver-0",
"containerType": "VMAppContainer",
"backupManagementType": "AzureWorkload",
"datasourceType": "SQLDataBase",
"datasourceName": "msdb",
"datasourceId": "932350676859704517",
"datasourceContainerName": "Compute;SQLServerPMDemo;sqlserver-0",
"coordinatorServiceStampId": "00000000-0000-0000-0000-000000000000",
"coordinatorServiceStampUri": "https://pod01-wbcm1.eus.backup.windowsazure.com",
"protectionServiceStampId": "00000000-0000-0000-0000-000000000000",
"protectionServiceStampUri": "https://pod01-prot1j-int.eus.backup.windowsazure.com",
"rpOriginalSAOption": false,
"rpIsManagedVirtualMachine": false,
"bMSActiveRegion": "EastUS"
},
"restoreRequest": {
"objectType": "AzureWorkloadSQLRestoreRequest",
"shouldUseAlternateTargetLocation": true,
"isNonRecoverable": false,
"alternateDirectoryPaths": [],
"recoveryType": "AlternateLocation",
"sourceResourceId":"/subscriptions/600000000-0000-0000-0000-000000000000/resourceGroups/SQLServerPMDemo/providers/Microsoft.Compute/virtualMachines/sqlserver-0",
"targetInfo": {
"overwriteOption": "FailOnConflict",
"containerId":"/Subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/RestoreRG/providers/Microsoft.RecoveryServices/vaults/wusRestoreVault/backupFabrics/Azure/protectionContainers/vmappcontainer;compute;restorerg;wusrestorevm",
"databaseName": "MSSQLSERVER/msdb_restored_8_1_2021_1758"
}
}
}
对受快照策略保护的 SQL 实例执行跨区域时间点恢复
利用该流程恢复 SQL 实例快照中包含的数据库,并将日志备份重放到次级区域的同一时间点。
Important
选定的时间点必须被你想从实例快照中恢复的每个数据库的日志范围覆盖。 请求用于 SQL 实例受保护项和所选具体快照恢复点的访问令牌。
发现实例快照和日志范围
列出 SQL 实例保护项的恢复点。
GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{sourceVaultResourceGroup}/providers/Microsoft.RecoveryServices/vaults/{sourceVaultName}/backupFabrics/Azure/protectionContainers/{sourceContainerName}/protectedItems/SQLInstance%3Bmssqlserver/recoveryPoints?api-version=2023-01-15选择一个响应包含以下所有值的恢复点:
-
properties.type是SnapshotFull。 -
properties.crossRegionRestoreState是Supported。 -
properties.recoveryPointTierDetails包含一个状态为Valid的HardenedRP条目。
-
获取选定的恢复点以获取其权威扩展信息。
GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{sourceVaultResourceGroup}/providers/Microsoft.RecoveryServices/vaults/{sourceVaultName}/backupFabrics/Azure/protectionContainers/{sourceContainerName}/protectedItems/SQLInstance%3Bmssqlserver/recoveryPoints/{instanceSnapshotRecoveryPointId}?api-version=2023-01-15使用
properties.extendedInfo.includedDatabases识别快照中包含的子数据库。 响应还包含恢复所需的源磁盘路径和快照元数据。获取 SQL 实例受保护项,并保存
properties.protectedItemDataSourceId。GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{sourceVaultResourceGroup}/providers/Microsoft.RecoveryServices/vaults/{sourceVaultName}/backupFabrics/Azure/protectionContainers/{sourceContainerName}/protectedItems/SQLInstance%3Bmssqlserver?api-version=2023-01-15对于每个包含的数据库,列出与所选实例快照相关的日志范围。
GET "https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{sourceVaultResourceGroup}/providers/Microsoft.RecoveryServices/vaults/{sourceVaultName}/backupFabrics/Azure/protectionContainers/{sourceContainerName}/protectedItems/SQLDataBase%3Bmssqlserver%3B{databaseName}/recoveryPoints?api-version=2023-01-15&$filter=restorePointQueryType eq 'Log' and recoveryMode eq 'SnapshotAttachAndRecover' and baseSnapshotRPId eq '{instanceSnapshotRecoveryPointId}' and baseRPDatasourceId eq '{instanceProtectedItemDataSourceId}'"该响应包含一个
DefaultRangeRecoveryPoint。 为每个正在还原的数据库选择一个落在返回的pointInTime范围内的 UTCproperties.timeRanges。
获取实例快照的访问令牌
获取次级区域的 Microsoft Entra 属性。
GET "https://management.azure.com/subscriptions/{subscriptionId}/providers/Microsoft.RecoveryServices/locations/{secondaryRegion}/backupAadProperties?api-version=2023-01-15&$filter=backupManagementType eq 'AzureWorkload'"
当你为 SQL 实例和所选快照恢复点请求访问令牌时,将返回的 properties 对象传递到请求体中。
POST https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{sourceVaultResourceGroup}/providers/Microsoft.RecoveryServices/vaults/{sourceVaultName}/backupFabrics/Azure/protectionContainers/{sourceContainerName}/protectedItems/SQLInstance%3Bmssqlserver/recoveryPoints/{instanceSnapshotRecoveryPointId}/accessToken?api-version=2023-01-15
{
"properties": {
"tenantId": "<tenant-id>",
"audience": "<audience-returned-by-the-service>",
"servicePrincipalObjectId": "<service-principal-object-id>",
"identityVersion": 1
}
}
触发 SQL 实例的时间点恢复
将 AzureWorkloadSQLPointInTimeRestoreRequest 与 SnapshotAttachAndRecover 结合使用。 将访问令牌响应中的完整 properties 对象复制到 crossRegionRestoreAccessDetails。
POST https://management.azure.com/subscriptions/{subscriptionId}/providers/Microsoft.RecoveryServices/locations/{secondaryRegion}/backupCrossRegionRestore?api-version=2023-01-15
{
"crossRegionRestoreAccessDetails": {
"objectType": "WorkloadCrrAccessToken",
"accessTokenString": "<access-token-string>",
"recoveryPointId": "<instance-snapshot-recovery-point-id>",
"datasourceType": "SQLInstance",
"datasourceName": "mssqlserver"
},
"restoreRequest": {
"objectType": "AzureWorkloadSQLPointInTimeRestoreRequest",
"shouldUseAlternateTargetLocation": true,
"recoveryMode": "SnapshotAttachAndRecover",
"isNonRecoverable": false,
"recoveryType": "AlternateLocation",
"sourceResourceId": "/subscriptions/{subscriptionId}/resourceGroups/{sourceVmResourceGroup}/providers/Microsoft.Compute/virtualMachines/{sourceVmName}",
"targetVirtualMachineId": "/subscriptions/{subscriptionId}/resourceGroups/{targetVmResourceGroup}/providers/Microsoft.Compute/virtualMachines/{targetVmName}",
"targetResourceGroupName": "{targetVmResourceGroup}",
"pointInTime": "2026-08-09T17:18:23.500Z",
"alternateDirectoryPaths": [
{
"mappingType": "DiskDrives",
"sourcePath": "F:\\",
"targetPath": "J:\\"
},
{
"mappingType": "DiskDrives",
"sourcePath": "G:\\",
"targetPath": "K:\\"
}
],
"targetInfo": {
"containerId": "/subscriptions/{subscriptionId}/resourceGroups/{targetVaultResourceGroup}/providers/Microsoft.RecoveryServices/vaults/{targetVaultName}/backupFabrics/Azure/protectionContainers/{targetContainerName}",
"overwriteOption": "FailOnConflict",
"databaseName": "MSSQLSERVER/*_{databaseNameSuffix}"
},
"userAssignedManagedIdentityDetails": {
"identityArmId": "/subscriptions/{subscriptionId}/resourceGroups/{identityResourceGroup}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}",
"userAssignedIdentityProperties": {
"clientId": "<managed-identity-client-id>",
"principalId": "<managed-identity-principal-id>"
}
}
}
}
上述 crossRegionRestoreAccessDetails 对象为精简摘要,仅展示用于标识实例场景的字段。 在实际请求中,复制访问令牌 API 返回的所有属性,包括 tokenExtendedInformation(如果存在)。
对受快照策略保护的子数据库执行跨区域日志恢复
当数据库作为 SQL 实例快照策略的一部分受到保护时,可使用此流程将单个子数据库还原到指定时间点。
Important
对于子数据库日志还原,请针对子 SQLDataBase 受保护项和 DefaultRangeRecoveryPoint 请求访问令牌。 不要在父SQL实例恢复点请求令牌。
发现子数据库日志范围
列出子数据库受保护项的日志恢复点。
GET "https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{sourceVaultResourceGroup}/providers/Microsoft.RecoveryServices/vaults/{sourceVaultName}/backupFabrics/Azure/protectionContainers/{sourceContainerName}/protectedItems/SQLDataBase%3Bmssqlserver%3B{databaseName}/recoveryPoints?api-version=2023-01-15&$filter=restorePointQueryType eq 'Log'"
响应包含一个 DefaultRangeRecoveryPoint,其中包含一个或多个 UTC 时间范围:
{
"value": [
{
"name": "DefaultRangeRecoveryPoint",
"properties": {
"objectType": "AzureWorkloadSQLPointInTimeRecoveryPoint",
"timeRanges": [
{
"startTime": "2026-07-26T19:25:29.9811766Z",
"endTime": "2026-08-10T18:31:23Z"
}
],
"type": "Log"
}
}
]
}
选择返回的某个范围内的 UTC pointInTime。
获取子数据库日志范围的访问令牌
通过SQL实例部分显示的Azure工作负载过滤器获取次级区域的Microsoft Entra属性。 请求子数据库访问令牌时,传递返回的 properties 对象。
POST https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{sourceVaultResourceGroup}/providers/Microsoft.RecoveryServices/vaults/{sourceVaultName}/backupFabrics/Azure/protectionContainers/{sourceContainerName}/protectedItems/SQLDataBase%3Bmssqlserver%3B{databaseName}/recoveryPoints/DefaultRangeRecoveryPoint/accessToken?api-version=2023-01-15
返回的访问令牌属性通过以下值标识所选子数据库:
{
"properties": {
"protectableObjectUniqueName": "MSSQLSERVER/{databaseName}",
"protectableObjectFriendlyName": "{databaseName}",
"objectType": "WorkloadCrrAccessToken",
"accessTokenString": "<access-token-string>",
"recoveryPointId": "DefaultRangeRecoveryPoint",
"datasourceType": "SQLDataBase",
"datasourceName": "{databaseName}"
}
}
触发子数据库日志恢复
将 AzureWorkloadSQLPointInTimeRestoreRequest 与 SnapshotAttachAndRecover 结合使用。 目标数据库名称必须使用 MSSQLSERVER/{targetDatabaseName} 逻辑路径格式。
POST https://management.azure.com/subscriptions/{subscriptionId}/providers/Microsoft.RecoveryServices/locations/{secondaryRegion}/backupCrossRegionRestore?api-version=2023-01-15
{
"crossRegionRestoreAccessDetails": {
"objectType": "WorkloadCrrAccessToken",
"accessTokenString": "<access-token-string>",
"recoveryPointId": "DefaultRangeRecoveryPoint",
"datasourceType": "SQLDataBase",
"datasourceName": "{databaseName}"
},
"restoreRequest": {
"objectType": "AzureWorkloadSQLPointInTimeRestoreRequest",
"shouldUseAlternateTargetLocation": true,
"recoveryMode": "SnapshotAttachAndRecover",
"isNonRecoverable": false,
"recoveryType": "AlternateLocation",
"sourceResourceId": "/subscriptions/{subscriptionId}/resourceGroups/{sourceVmResourceGroup}/providers/Microsoft.Compute/virtualMachines/{sourceVmName}",
"targetVirtualMachineId": "/subscriptions/{subscriptionId}/resourceGroups/{targetVmResourceGroup}/providers/Microsoft.Compute/virtualMachines/{targetVmName}",
"targetResourceGroupName": "{targetVmResourceGroup}",
"pointInTime": "2026-08-03T06:58:26Z",
"alternateDirectoryPaths": [
{
"mappingType": "DiskDrives",
"sourcePath": "F:\\",
"targetPath": "J:\\"
},
{
"mappingType": "DiskDrives",
"sourcePath": "G:\\",
"targetPath": "K:\\"
}
],
"targetInfo": {
"containerId": "/subscriptions/{subscriptionId}/resourceGroups/{targetVaultResourceGroup}/providers/Microsoft.RecoveryServices/vaults/{targetVaultName}/backupFabrics/Azure/protectionContainers/{targetContainerName}",
"overwriteOption": "FailOnConflict",
"databaseName": "MSSQLSERVER/{targetDatabaseName}"
},
"userAssignedManagedIdentityDetails": {
"identityArmId": "/subscriptions/{subscriptionId}/resourceGroups/{identityResourceGroup}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}",
"userAssignedIdentityProperties": {
"clientId": "<managed-identity-client-id>",
"principalId": "<managed-identity-principal-id>"
}
}
}
}
与实例请求一样,将完整的访问令牌 properties 对象复制到 crossRegionRestoreAccessDetails。 请将 accessTokenString 和 tokenExtendedInformation 视为机密信息,不要将其写入日志,也不要包含在共享产物中。
对于这两种时间点情景,触发都是异步的。 遵循 Azure-AsyncOperation、Location 和 Retry-After 响应头,并在将恢复视为成功之前,验证生成的 Recovery Services 保管库作业的最终状态。
后续步骤
使用 Azure 门户、 Azure CLI、 REST API 管理 Azure VM 中的 SQL Server 数据库。
有关 Azure 备份 REST API 的详细信息,请参阅以下文档: