使用专用链接导入或导出 Azure SQL 数据库

适用于:Azure SQL 数据库

要通过 Azure PowerShell 或 Azure 门户运行导入或导出,需要将允许访问 Azure 服务设置为“打开”,否则导入或导出操作将会失败并出现错误。 用户往往希望能够使用专用终结点执行导入或导出,而不需要访问所有 Azure 服务。 本文介绍如何在 Azure SQL 逻辑服务器上将“允许访问 Azure 服务”设置为保持“关闭”的情况下,使用专用链接导入或导出 Azure SQL 数据库。

注意

使用专用链接导入/导出 Azure SQL 数据库的功能目前以预览版提供。

数据库导入/导出专用链接是 Azure 创建的服务托管专用终结点,专门由数据库导入/导出流程、Azure SQL 数据库以及相关 Azure 存储服务用来进行各种通信。 服务托管的专用终结点是特定虚拟网络和子网中的专用 IP 地址。 用于服务器和存储的专用终结点必须由用户在 Azure 门户中手动批准。

Diagram of Import Export Private link architecture.

可以通过 Azure 门户、PowerShell 或使用 REST API 配置导入/导出专用链接。

  1. 转到要在其中导入数据库的 Azure SQL 逻辑服务器的“概述”页。 从工具栏中选择“导入数据库”。
  2. 在“导入数据库”页中,选中“使用专用链接”选项复选框。 Screenshot from the Azure portal that shows how to enable Import Private link.
  3. 输入存储帐户、身份验证凭据、数据库详细信息,然后选择“确定”。
  1. 转到要导出的 Azure SQL 数据库的“概述”页。 从工具栏中选择“导出”。
  2. 在“导出数据库”页中,选中“使用专用链接”选项复选框。 Screenshot from the Azure portal that shows how to enable Export Private Link.
  3. 输入存储帐户、身份验证凭据、数据库详细信息,然后选择“确定”。

2. 批准专用终结点

  1. 转到 Azure 门户中的专用链接中心。 在 Azure 搜索框中,搜索“专用链接”。
  2. 导航到专用链接中心的“专用终结点”页。
  3. 批准使用导入/导出服务创建的专用终结点。

批准 Azure SQL 数据库上的专用终结点连接

  1. 转到托管数据库的 Azure SQL 逻辑服务器。
  2. 导航到“安全”下的“网络”页
  3. 选择“专用访问”选项卡。
  4. 选择要批准的专用终结点。
  5. 选择“批准”以批准连接。

Screenshot from the Azure portal that shows how to approve Azure SQL Database Private Link.

批准 Azure 存储上的专用终结点连接

  1. 转到托管了包含 .bacpac 文件的 Blob 容器的存储帐户。
  2. 在“安全”菜单中打开“专用终结点连接”页。
  3. 选择导入/导出服务的专用终结点。
  4. 选择“批准”以批准连接。

Screenshot from the Azure portal that shows how to approve Azure Storage Private Link in Azure Storage.

3. 检查导入/导出状态

  1. 在 Azure SQL 服务器和 Azure 存储帐户中批准专用终结点后,将启动数据库导入或导出作业。 在此之前,这些作业一直处于搁置状态。
  2. 可以在“Azure SQL Server”页的“数据管理”部分下的“导入/导出历史记录”页中检查数据库导入或导出作业的状态。 Screenshot from the Azure portal that shows how to check Import Export Jobs Status.

使用 New-AzSqlDatabaseImport cmdlet 向 Azure 提交导入数据库请求。 根据数据库大小,导入操作可能需要一些时间才能完成。 基于 DTU 的预配模型支持为每个层选择数据库最大大小值。 导入数据库时,请使用其中一种受支持的值

$importRequest = New-AzSqlDatabaseImport -ResourceGroupName "<resourceGroupName>" `
        -ServerName "<serverName>" -DatabaseName "<databaseName>" `
        -DatabaseMaxSizeBytes "<databaseSizeInBytes>" -StorageKeyType "StorageAccessKey" `
        -StorageKey $(Get-AzStorageAccountKey -ResourceGroupName $resourceGroupName `
                        -StorageAccountName "<storageAccountName>").Value[0]
        -StorageUri "https://myStorageAccount.blob.core.chinacloudapi.cn/importsample/sample.bacpac" `
        -Edition "Standard" -ServiceObjectiveName "P6" ` -UseNetworkIsolation $true `
        -StorageAccountResourceIdForPrivateLink "/subscriptions/<subscriptionId>/resourcegroups/<resource_group_name>/providers/Microsoft.Storage/storageAccounts/<storage_account_name>" `
         -SqlServerResourceIdForPrivateLink "/subscriptions/<subscriptionId>/resourceGroups/<resource_group_name>/providers/Microsoft.Sql/servers/<server_name>" `
        -AdministratorLogin "<userID>" `
        -AdministratorLoginPassword $(ConvertTo-SecureString -String "<password>" -AsPlainText -Force)

使用 New-AzSqlDatabaseExport cmdlet 向 Azure SQL 数据库服务提交导出数据库请求。 根据数据库的大小,导出操作可能需要一些时间才能完成。

$importRequest = New-AzSqlDatabaseExport -ResourceGroupName "<resourceGroupName>" `
        -ServerName "<serverName>" -DatabaseName "<databaseName>" `
        -DatabaseMaxSizeBytes "<databaseSizeInBytes>" -StorageKeyType "StorageAccessKey" `
        -StorageKey $(Get-AzStorageAccountKey -ResourceGroupName $resourceGroupName `
                        -StorageAccountName "<storageAccountName>").Value[0]
        -StorageUri "https://myStorageAccount.blob.core.chinacloudapi.cn/importsample/sample.bacpac" `
        -Edition "Standard" -ServiceObjectiveName "P6" ` -UseNetworkIsolation $true `
        -StorageAccountResourceIdForPrivateLink "/subscriptions/<subscriptionId>/resourcegroups/<resource_group_name>/providers/Microsoft.Storage/storageAccounts/<storage_account_name>" `
         -SqlServerResourceIdForPrivateLink "/subscriptions/<subscriptionId>/resourceGroups/<resource_group_name>/providers/Microsoft.Sql/servers/<server_name>" `
        -AdministratorLogin "<userID>" `
        -AdministratorLoginPassword $(ConvertTo-SecureString -String "<password>" -AsPlainText -Force)

用于执行导入和导出作业的现有 API 已得到增强,现在支持专用链接。 请参阅 导入数据库 API

限制

目前,用于导入/导出的专用链接具有以下限制:

  • 目前不支持使用 PowerShell 从 Azure SQL 托管实例导入或导出数据库。

  • 当用户数据库或 Azure 存储帐户受资源锁保护时,不应使用导入/导出专用链接。

  • 需要手动批准新的专用终结点连接才能完成导出操作。 开始导出后,转到专用链接中心的“挂起的连接”并批准连接,这可能需要几分钟才能显示。

  • 使用专用链接进行导入操作不支持在创建新数据库时指定备份存储冗余,而是会使用默认异地冗余备份存储冗余创建新的数据库。 解决方法是首先使用 Azure 门户或 PowerShell 和所需的备份存储冗余创建一个空数据库,然后将 .bacpac 文件导入这个空数据库。

  • 结合使用专用链接和 REST API 的导入操作只能对现有数据库执行,因为 API 使用数据库扩展名。 解决方法是创建一个具有所需名称的空数据库,然后使用专用链接调用导入 REST API。

后续步骤