通过 REST API 使用 Azure 备份在 Azure VM 中备份 SQL Server 数据库

本文介绍如何通过 REST API 使用 Azure 备份在 Azure VM 中备份 SQL Server 数据库。

注意

若要详细了解支持的配置和场景,请参阅 SQL 备份支持矩阵

先决条件

  • 恢复服务保管库
  • 用于为 SQL 数据库配置备份的策略。

有关如何创建新的保管库和策略的详细信息,请参阅创建保管库创建策略 REST API 教程。

使用以下资源:

  • 恢复服务保管库:SQLServer2012
  • 策略:HourlyLogBackup
  • 资源组:SQLServerSelfHost

在 Azure VM 中为不受保护的 SQL Server 数据库配置备份

发现不受保护的 SQL Server 数据库

保管库需要发现订阅中的所有 Azure VM,其中包含可备份到恢复服务保管库的 SQL 数据库。 要获取详细信息,请触发刷新操作。 这是一种异步 POST 操作,可确保保管库接收当前订阅中所有不受保护的 SQL 数据库的最新列表,并缓存它们 。 缓存数据库后,恢复服务便可访问数据库并对其进行保护。

POST https://management.chinacloudapi.cn/subscriptions/{subscriptionId}/resourceGroups/{vaultResourceGroupName}/providers/microsoft.recoveryservices/vaults/{vaultName}/backupFabrics/{fabricName}/refreshContainers?api-version=2016-12-01&$filter={$filter}

POST URI 包含参数 {subscriptionId}{vaultName}{vaultresourceGroupName}{fabricName}。 在以下示例中,不同参数的值如下所示:

  • {fabricName}:Azure
  • {vaultName}:SQLServer2012
  • {vaultresourceGroupName}:SQLServerSelfHost
  • $filter:backupManagementType eq 'AzureWorkload'

由于 URI3 中给出了所有必需的参数,因此不需要单独的请求正文。

POST https://management.chinacloudapi.cn/subscriptions/00000000-0000-0000-0000-0000000000/resourceGroups/SQLServerSelfHost/providers/microsoft.recoveryservices/vaults/SQLServer2012/backupFabrics/Azure/refreshContainers?api-version=2016-12-01&$filter=backupManagementType eq 'AzureWorkload'

针对“刷新”操作的响应

“刷新”操作是一种异步操作。 这意味着,此操作会创建另一个需要单独跟踪的操作。

它将返回两个响应:创建另一个操作时为 202(已接受),该操作完成时为 200(确定)。

针对“刷新”操作的响应示例

提交 POST 请求后,将返回 202(已接受)响应。

HTTP/1.1 202 Accepted
Pragma: no-cache
Retry-After: 60
X-Content-Type-Options: nosniff
x-ms-request-id: a85ee4a2-56d7-4477-b29c-d140a8bb90fe
x-ms-client-request-id: 4653a4ed-ffbe-4492-ae7d-3e1ab03722af; 4653a4ed-ffbe-4492-ae7d-3e1ab03722af
Strict-Transport-Security: max-age=31536000; includeSubDomains
x-ms-ratelimit-remaining-subscription-writes: 1199
x-ms-correlation-request-id: a85ee4a2-56d7-4477-b29c-d140a8bb90fe
x-ms-routing-request-id: CHINAEAST:20180528T075517Z:a85ee4a2-56d7-4477-b29c-d140a8bb90fe
Cache-Control: no-cache
Date: Mon, 28 May 2018 07:55:16 GMT
Location: https://management.chinacloudapi.cn/subscriptions/00000000-0000-0000-0000-0000000000/resourceGroups/SQLServerSelfHost/providers/microsoft.recoveryservices/vaults/SQLServer2012/backupFabrics/Azure/operationResults/a60bfc5e-e237-4ead-be5c-b845e9566ea8?api-version=2016-12-01
X-Powered-By: ASP.NET

使用带有简单 GET 命令的“Location”标头跟踪生成的操作 。

GET https://management.chinacloudapi.cn/subscriptions/00000000-0000-0000-0000-0000000000/resourceGroups/SQLServerSelfHost/providers/microsoft.recoveryservices/vaults/SQLServer2012/backupFabrics/Azure/operationResults/a60bfc5e-e237-4ead-be5c-b845e9566ea8?api-version=2016-12-01

一旦发现所有 SQL 数据库后,GET 命令将返回 200(无内容)响应。 保管库现可发现任何具有可在订阅中备份的 SQL 数据库的 VM。

HTTP/1.1 204 NoContent
Pragma: no-cache
X-Content-Type-Options: nosniff
x-ms-request-id: 55ae46bb-0d61-4284-a408-bcfaa36af643
x-ms-client-request-id: b5ffa56f-a521-48a4-91b2-e3bc1e3f1110; b5ffa56f-a521-48a4-91b2-e3bc1e3f1110
Strict-Transport-Security: max-age=31536000; includeSubDomains
x-ms-ratelimit-remaining-subscription-reads: 14968
x-ms-correlation-request-id: 55ae46bb-0d61-4284-a408-bcfaa36af643
x-ms-routing-request-id: CHINAEAST:20180528T075607Z:55ae46bb-0d61-4284-a408-bcfaa36af643
Cache-Control: no-cache
Date: Mon, 28 May 2018 07:56:06 GMT
X-Powered-By: ASP.NET

列出具有要使用恢复服务保管库备份的 SQL 数据库的 VM

若要确认已完成“缓存”,请列出订阅中的所有 VM,其中包含可通过恢复服务保管库备份的 SQL 数据库。 然后在响应中找到所需存储帐户。 这可以使用 GET ProtectableContainers 操作来完成。

GET https://management.chinacloudapi.cn/subscriptions/00000000-0000-0000-0000-0000000000/resourceGroups/SQLServerSelfHost/providers/microsoft.recoveryservices/vaults/SQLServer2012/backupFabrics/Azure/protectableContainers?api-version=2016-12-01&$filter=backupManagementType eq 'AzureWorkload'

注意

GET URI 包含所有必需的参数。 无需额外的请求正文。

响应正文的示例:

{
  "value": [
    {
      "id": "/subscriptions/00000000-0000-0000-0000-0000000000/resourceGroups/SQLServerSelfHost/providers/microsoft.recoveryservices/vaults/SQLServer2012/backupFabrics/Azure/protectableContainers/VMAppContainer;Compute;SQLServerPMDemo;ad-primary-dc",
      "name": "VMAppContainer;Compute;SQLServerPMDemo;ad-primary-dc",
      "type": "Microsoft.RecoveryServices/vaults/backupFabrics/protectableContainers",
      "properties": {
        "friendlyName": "ad-primary-dc",
        "backupManagementType": "AzureWorkload",
        "protectableContainerType": "VMAppContainer",
        "healthStatus": "Healthy",
        "containerId": "/subscriptions/00000000-0000-0000-0000-0000000000/resourceGroups/SQLServerPMDemo/providers/Microsoft.Compute/virtualMachines/ad-primary-dc"
      }
    },
    {
      "id": "/subscriptions/00000000-0000-0000-0000-0000000000/resourceGroups/SQLServerSelfHost/providers/microsoft.recoveryservices/vaults/SQLServer2012/backupFabrics/Azure/protectableContainers/VMAppContainer;Compute;SQLServerPMDemo;ad-secondry-dc",
      "name": "VMAppContainer;Compute;SQLServerPMDemo;ad-secondry-dc",
      "type": "Microsoft.RecoveryServices/vaults/backupFabrics/protectableContainers",
      "properties": {
        "friendlyName": "ad-secondry-dc",
        "backupManagementType": "AzureWorkload",
        "protectableContainerType": "VMAppContainer",
        "healthStatus": "Healthy",
        "containerId": "/subscriptions/00000000-0000-0000-0000-0000000000/resourceGroups/SQLServerPMDemo/providers/Microsoft.Compute/virtualMachines/ad-secondry-dc"
      }
    },
    {
      "id": "/subscriptions/00000000-0000-0000-0000-0000000000/resourceGroups/SQLServerSelfHost/providers/microsoft.recoveryservices/vaults/SQLServer2012/backupFabrics/Azure/protectableContainers/VMAppContainer;Compute;SQLServerPMDemo;sqlserver-0",
      "name": "VMAppContainer;Compute;SQLServerPMDemo;sqlserver-0",
      "type": "Microsoft.RecoveryServices/vaults/backupFabrics/protectableContainers",
      "properties": {
        "friendlyName": "sqlserver-0",
        "backupManagementType": "AzureWorkload",
        "protectableContainerType": "VMAppContainer",
        "healthStatus": "Healthy",
        "containerId": "/subscriptions/00000000-0000-0000-0000-0000000000/resourceGroups/SQLServerPMDemo/providers/Microsoft.Compute/virtualMachines/sqlserver-0"
      }
    }
  ]
}

由于我们可以在响应正文中找到具有易记名称的 VM,因此已成功执行上述刷新操作。 恢复服务保管库现在可以成功发现同一订阅中具有不受保护的 SQL 数据库的 VM。

向恢复服务保管库注册 VM

需要将 VM 注册到恢复服务保管库,以便 Azure 备份服务可与 VM 中的 SQL 数据库进行交互(使用 Name 字段中的值来标识 Azure VM 容器)。 需要在 JSON 请求中提供值,以从列表可保护容器结果的属性包中获取 HTTP 请求正文。

PUT https://management.chinacloudapi.cn/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.recoveryservices/vaults/{vaultName}/backupFabrics/Azure/protectionContainers/{containerName}?api-version=2016-12-01

按如下所示设置 URI 的变量:

  • {resourceGroupName} - SQLServerSelfHost
  • {fabricName} - Azure
  • {vaultName} - SQLServer2012
  • {containerName} - 这是 GET ProtectableContainers 操作的响应正文中的 name 属性。 在该示例中,属性名称为 VMAppContainer;Compute;SQLServerPMDemo;sqlserver-0。

注意

始终采用响应的 name 属性,并填入此请求。 不得硬编码或创建容器名称格式。 如果创建或硬编码了此容器,则在将来容器名称格式发生变化时,API 调用将失败。


PUT https://management.chinacloudapi.cn/subscriptions/00000000-0000-0000-0000-0000000000/resourceGroups/SQLServerSelfHost/providers/microsoft.recoveryservices/vaults/SQLServer2012/backupFabrics/Azure/protectionContainers/VMAppContainer;Compute;SQLServerPMDemo;sqlserver-0?api-version=2016-12-01

创建请求正文如下所示:

{
  "properties": {
    "backupManagementType": "AzureWorkload",
    "friendlyName": "sqlserver-0",
    "containerType": "VMAppContainer",
    "sourceResourceId": "/subscriptions/00000000-0000-0000-0000-0000000000/resourceGroups/SQLServerSelfHost/providers/microsoft.recoveryservices/vaults/SQLServer2012/backupFabrics/Azure/protectableContainers/VMAppContainer;Compute;SQLServerPMDemo;sqlserver-0",
    "workloadType": "SQLDataBase"
  }
}

有关请求正文的完整定义列表和其他详细信息,请参阅 ProtectionContainers-Register

这是一种异步操作,可返回两个响应:接受操作时为 202(已接受),操作完成时为200(确定)。 若要跟踪操作状态,请使用位置标头获取操作的最新状态。

GET https://management.chinacloudapi.cn/subscriptions/00000000-0000-0000-0000-0000000000/resourceGroups/SQLServerSelfHost/providers/microsoft.recoveryservices/vaults/SQLServer2012/backupFabrics/Azure/protectionContainers/VMAppContainer;Compute;SQLServerPMDemo;sqlserver-0/operationResults/2a72d206-b4d8-4c59-89ef-ef3283132237?api-version=2016-12-01

操作完成时响应正文的示例:

{
  "id": "/subscriptions/00000000-0000-0000-0000-0000000000/resourceGroups/SQLServerSelfHost/providers/microsoft.recoveryservices/vaults/SQLServer2012/backupFabrics/Azure/protectionContainers/VMAppContainer;Compute;SQLServerPMDemo;sqlserver-0",
  "name": "VMAppContainer;Compute;SQLServerPMDemo;sqlserver-0",
  "type": "Microsoft.RecoveryServices/vaults/backupFabrics/protectionContainers",
  "properties": {
    "sourceResourceId": "/subscriptions/00000000-0000-0000-0000-0000000000/resourceGroups/SQLServerPMDemo/providers/Microsoft.Compute/virtualMachines/sqlserver-0",
    "lastUpdatedTime": "2018-05-28T08:33:14.7304852Z",
    "extendedInfo": {
      "hostServerName": "sqlserver-0.shopkart.com",
      "inquiryInfo": {
        "status": "Success",
        "errorDetail": {
          "code": "Success",
          "message": "",
          "recommendations": [
            ""
          ]
        },
        "inquiryDetails": [
          {
            "type": "SQL",
            "itemCount": 5,
            "inquiryValidation": {
              "status": "Success",
              "errorDetail": {
                "code": "Success",
                "message": "",
                "recommendations": [
                  ""
                ]
              }
            }
          }
        ]
      }
    },
    "friendlyName": "sqlserver-0",
    "backupManagementType": "AzureWorkload",
    "registrationStatus": "Registered",
    "healthStatus": "Healthy",
    "containerType": "VMAppContainer",
    "protectableObjectType": "VMAppContainer"
  }
}

可以根据响应正文中 registrationstatus 参数的值验证注册是否成功。 在本实例中,显示的是为 SQLServer2012 注册的状态,因此注册操作成功。

查询 VM 中所有不受保护的 SQL 数据库

要查询存储帐户中的可保护项,请使用 Protection Containers-Inquire 操作。 这是一种异步操作,应使用位置标头跟踪结果。

POST https://management.chinacloudapi.cn/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupFabrics/{fabricName}/protectionContainers/{containerName}/inquire?api-version=2016-12-01$filter={$filter}

按如下所示设置上述 URI 的变量:

  • {resourceGroupName}:SQLServerSelfHost
  • {vaultName}:SQLServer2012
  • {fabricName}:Azure
  • {containerName}:请参阅 GET ProtectableContainers 操作的响应正文中的 name 属性。 在该示例中,属性名称为 VMAppContainer;Compute;SQLServerPMDemo;sqlserver-0。
POST https://management.chinacloudapi.cn/subscriptions/e3d2d341-4ddb-4c5d-9121-69b7e719485e/resourceGroups/SQLServerSelfHost/providers/microsoft.recoveryservices/vaults/SQLServer2012/backupFabrics/Azure/protectionContainers/VMAppContainer;Compute;SQLServerPMDemo;sqlserver-0/inquire?api-version=2016-12-01$filter=workloadType EQ 'SQLDatabase'

请求成功后,系统将返回状态代码“确定”。

HTTP/1.1 202 Accepted
Pragma: no-cache
Retry-After: 60
X-Content-Type-Options: nosniff
x-ms-request-id: 50295ae9-3d5b-48d1-8a6d-a0acb6d06b98
x-ms-client-request-id: 4174f98a-80b9-4747-9500-6f702ed83930; 4174f98a-80b9-4747-9500-6f702ed83930
Strict-Transport-Security: max-age=31536000; includeSubDomains
x-ms-ratelimit-remaining-subscription-writes: 1197
x-ms-correlation-request-id: 50295ae9-3d5b-48d1-8a6d-a0acb6d06b98
x-ms-routing-request-id: CHINAEAST:20180528T084628Z:50295ae9-3d5b-48d1-8a6d-a0acb6d06b98
Cache-Control: no-cache
Date: Mon, 28 May 2018 08:46:28 GMT
Location: https://management.chinacloudapi.cn/subscriptions/00000000-0000-0000-0000-0000000000/resourceGroups/SQLServerSelfHost/providers/microsoft.recoveryservices/vaults/SQLServer2012/backupFabrics/Azure/protectionContainers/VMAppContainer;Compute;SQLServerPMDemo;sqlserver-0/operationResults/f0751ec2-445a-4d0e-a6a5-a19957459655?api-version=2016-12-01
X-Powered-By: ASP.NET

请选择要备份的数据库

若要列出订阅下的所有可保护项并找到需要备份的数据库,请使用 GET backupprotectableItems 操作。

GET https://management.chinacloudapi.cn/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupProtectableItems?api-version=2016-12-01&$filter={$filter}

按如下所示构造 URI:

  • {resourceGroupName}:SQLServerSelfHost
  • {vaultName}:SQLServer2012
  • {$filter}:backupManagementType eq 'AzureWorkload'
GET https://management.chinacloudapi.cn/subscriptions/00000000-0000-0000-0000-0000000000/resourceGroups/SQLServerSelfHost/providers/microsoft.recoveryservices/vaults/SQLServer2012/backupProtectableItems?api-version=2016-12-01&$filter=backupManagementType eq 'AzureWorkload'

示例响应:

Status Code:200

{
  "value": [
    {
      "id": "/subscriptions/00000000-0000-0000-0000-0000000000/resourceGroups/SQLServerSelfHost/providers/microsoft.recoveryservices/vaults/SQLServer2012/backupFabrics/Azure/protectionContainers/vmappcontainer;compute;SQLServerSelfHost;SQLServersql2012/protectableItems/sqldatabase;mssqlserver;msdb",
      "name": "sqldatabase;mssqlserver;msdb",
      "type": "Microsoft.RecoveryServices/vaults/backupFabrics/protectionContainers/protectableItems",
      "properties": {
        "parentName": "MSSQLSERVER",
        "serverName": "SQLServersql2012",
        "isAutoProtectable": false,
        "subinquireditemcount": 0,
        "subprotectableitemcount": 0,
        "backupManagementType": "AzureWorkload",
        "workloadType": "SQL",
        "protectableItemType": "SQLDataBase",
        "friendlyName": "msdb",
        "protectionState": "NotProtected"
      }
    }
]
}

响应包含所有未受保护的数据库的列表,并包含 Azure 恢复服务配置备份所需的所有信息。 保存数据库名称,以供将来使用。

为数据库启用备份

在使用易记名称标识相关数据库后,请执行以下操作:

  1. 选择要保护的策略。
  2. 列出保管库中的现有策略,请参阅列出策略 API
  3. 通过引用策略名称来选择相关策略
  4. 创建策略教程

启用保护是一种异步 PUT 操作,可创建“受保护的项” 。

PUT https://management.chinacloudapi.cn/subscriptions/00000000-0000-0000-0000-0000000000/resourceGroups/SQLServerSelfHost/providers/microsoft.recoveryservices/vaults/SQLServer2012/backupFabrics/Azure/protectionContainers/{containerName};sqlserver-0/protectedItems/{protectedItemName}?api-version=2016-12-01

使用 GET backupprotectableitems 操作的响应正文中的 ID 属性设置 containerName 和 protectedItemName 变量 。

在我们的示例中,要保护的文件共享的 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

创建请求正文:

以下请求正文定义创建受保护项所需的属性。

{
  "properties": {
    "backupManagementType": "AzureWorkload",
    "workloadType": "SQLDataBase",
    "policyId": "/subscriptions/00000000-0000-0000-0000-0000000000/resourceGroups/SQLServerSelfHost/providers/microsoft.recoveryservices/vaults/SQLServer2012/backupPolicies/HourlyLogBackup"
  },
  "location": "chinaeast2"
}

一旦提交 “PUT” 请求以创建或更新受保护的项后,初始响应为 202(已接受),其中包含位置标头。

示例响应

创建受保护项是一种异步操作,该操作将创建另一个需要跟踪的操作。 它将返回两个响应:创建另一个操作时为 202(已接受),该操作完成时为 200(确定)。

一旦提交 “PUT” 请求以创建或更新受保护的项后,初始响应为 202(已接受),其中包含位置标头。

HTTP/1.1 202 Accepted
Pragma: no-cache
Retry-After: 60
Azure-AsyncOperation: https://management.chinacloudapi.cn/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/operationsStatus/b686a165-387f-461d-8579-c55338566338?api-version=2016-12-01
X-Content-Type-Options: nosniff
x-ms-request-id: ab6a8c6c-ab90-433a-8dc2-5194901d428d
x-ms-client-request-id: 7d03bcef-562a-4ddc-8086-a3f4981be915; 7d03bcef-562a-4ddc-8086-a3f4981be915
Strict-Transport-Security: max-age=31536000; includeSubDomains
x-ms-ratelimit-remaining-subscription-writes: 1199
x-ms-correlation-request-id: ab6a8c6c-ab90-433a-8dc2-5194901d428d
x-ms-routing-request-id: CHINAEAST:20180528T102112Z:ab6a8c6c-ab90-433a-8dc2-5194901d428d
Cache-Control: no-cache
Date: Mon, 28 May 2018 10:21:12 GMT
Location: https://management.chinacloudapi.cn/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/operationResults/b686a165-387f-461d-8579-c55338566338?api-version=2016-12-01
X-Powered-By: ASP.NET

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

GET https://management.chinacloudapi.cn/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/operationResults/b686a165-387f-461d-8579-c55338566338?api-version=2016-12-01

操作完成后,它将在响应正文中返回 200(确定),其中包含受保护的项内容。

示例响应正文:

{
  "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",
  "name": "SQLDataBase;mssqlserver;msdb",
  "type": "Microsoft.RecoveryServices/vaults/backupFabrics/protectionContainers/protectedItems",
  "properties": {
    "friendlyName": "msdb",
    "serverName": "sqlserver-0.shopkart.com",
    "parentName": "MSSQLSERVER",
    "parentType": "AzureVmWorkloadSQLInstance",
    "protectionStatus": "Healthy",
    "protectionState": "IRPending",
    "lastBackupStatus": "IRPending",
    "lastBackupErrorDetail": {
      "code": "Success",
      "message": ""
    },
    "protectedItemDataSourceId": "17592741727863",
    "protectedItemHealthStatus": "IRPending",
    "extendedInfo": {
      "recoveryPointCount": 0,
      "policyState": "Consistent"
    },
    "protectedItemType": "AzureVmWorkloadSQLDatabase",
    "backupManagementType": "AzureWorkload",
    "workloadType": "SQLDataBase",
    "containerName": "VMAppContainer;Compute;SQLServerPMDemo;sqlserver-0",
    "sourceResourceId": "/subscriptions/00000000-0000-0000-0000-0000000000/resourceGroups/SQLServerPMDemo/providers/VMAppContainer/sqlserver-0",
    "policyId": "/subscriptions/00000000-0000-0000-0000-0000000000/resourceGroups/SQLServerSelfHost/providers/microsoft.recoveryservices/vaults/SQLServer2012/backupPolicies/HourlyLogBackup"
  }
}

这确认了以下事实:已为数据库启用了保护,并且将根据策略计划触发第一次备份。

为数据库触发按需备份

配置数据库以进行备份后,将根据策略计划运行备份。 可以等待第一次计划备份或随时触发按需备份。

触发按需备份是一种 POST 操作。

注意

此备份的保持期取决于运行的按需备份的类型。

  • “按需完整备份”将备份保留最少 45 天,最多 99 年。
  • “按需仅复制完整备份”接受任何值进行保留。
  • “按需差异备份”根据策略中设置的计划差异保留来保留备份。
  • “按需日志备份”根据策略中设置的计划日志保留来保留备份。
POST https://management.chinacloudapi.cn/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupFabrics/{fabricName}/protectionContainers/{containerName}/protectedItems/{protectedItemName}/backup?api-version=2016-12-01

启用备份时,{containerName} 和 {protectedItemName} 将按上述方式构造。 对于我们的示例,这已转换为:

POST https://management.chinacloudapi.cn/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/backup?api-version=2016-12-01

创建请求正文

使用以下请求正文创建按需完整备份。

{
  "properties": {
    "objectType": "AzureWorkloadBackupRequest",
    "backupType": "Full"
  }
}

对按需备份操作的响应

触发按需备份是一种异步操作。 这意味着,此操作会创建另一个需要单独跟踪的操作。

它将返回两个响应:创建另一个操作时为 202(已接受),该操作完成时为 200(确定)。

对按需备份操作的响应示例

一旦提交按需备份的 POST 请求后,初始响应为 202(已接受),其中包含 location 标头或 Azure-async 标头。

HTTP/1.1 202 Accepted
Pragma: no-cache
Retry-After: 60
Azure-AsyncOperation: https://management.chinacloudapi.cn/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/operationsStatus/cd2a3b13-d392-4e81-86ac-02ea91cc70b9?api-version=2016-12-01
X-Content-Type-Options: nosniff
x-ms-request-id: a691e2a9-8203-462d-a4da-d1badde22f83
x-ms-client-request-id: 6b033cf6-f875-4c03-8985-9add07ec2845; 6b033cf6-f875-4c03-8985-9add07ec2845
Strict-Transport-Security: max-age=31536000; includeSubDomains
x-ms-ratelimit-remaining-subscription-writes: 1199
x-ms-correlation-request-id: a691e2a9-8203-462d-a4da-d1badde22f83
x-ms-routing-request-id: CHINAEAST:20180528T114321Z:a691e2a9-8203-462d-a4da-d1badde22f83
Cache-Control: no-cache
Date: Mon, 28 May 2018 11:43:21 GMT
Location: https://management.chinacloudapi.cn/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/operationResults/cd2a3b13-d392-4e81-86ac-02ea91cc70b9?api-version=2016-12-01
X-Powered-By: ASP.NET

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

GET https://management.chinacloudapi.cn/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/operationsStatus/cd2a3b13-d392-4e81-86ac-02ea91cc70b9?api-version=2016-12-01

操作完成时,它将在响应正文中返回 200(确定),其中包含生成的备份作业的 ID。

示例响应正文

{
  "id": "cd2a3b13-d392-4e81-86ac-02ea91cc70b9",
  "name": "cd2a3b13-d392-4e81-86ac-02ea91cc70b9",
  "status": "Succeeded",
  "startTime": "2018-05-28T11:43:21.6516182Z",
  "endTime": "2018-05-28T11:43:21.6516182Z",
  "properties": {
    "objectType": "OperationStatusJobExtendedInfo",
    "jobId": "c22eca5d-0c1c-48a0-a40d-69bef708d92a"
  }
}

由于备份作业是长时间运行的操作,因此需要按“使用 REST API 监视作业”文档中所述对其进行跟踪。

后续步骤