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

还原现有专用 SQL 池

本文介绍如何通过 Azure 门户、Synapse Studio 和 PowerShell 在 Azure Synapse Analytics 中还原现有专用 SQL 池。 本文适用于还原和异地还原。

注意

本指南仅适用于Azure Synapse工作区中的专用 SQL 池。 对于独立专用 SQL 池(以前称为 SQL DW),请参阅还原现有的专用 SQL 池(以前称为 SQL DW)

通过 Synapse Studio 还原现有专用 SQL 池

  1. 登录 Azure 门户

  2. 导航到 Azure Synapse 工作区。

  3. 在“入门”->“打开 Synapse Studio”下,选择“打开”>。 Screenshot from Synapse Studio, showing the Open Synapse Studio box and Open link.

  4. 在左侧导航窗格中,选择“数据”。

  5. 选择“管理池”。

  6. 选择“+ 新建”,以便在 Azure Synapse Analytics 工作区中创建一个新的专用 SQL 池。

  7. 在“其他设置”选项卡中,选择要从中还原的还原点。

    如果要执行异地还原,请选择要恢复的工作区和专用 SQL 池。

  8. 选择“自动还原点”或“用户定义的还原点”。

    Screenshot from the Azure portal, Create SQL pool page, Additional settings page. For Restore point type, the Automatic restore points radio button is selected.

    • 如果专用 SQL 池没有任何自动还原点,请等待数小时或创建一个用户定义的还原点,然后再进行还原。 对于用户定义的还原点,请选择一个现有的,或者创建一个新的。

    • 如果要从其他工作区还原专用 SQL 池,请从当前工作区中选择“新建专用 SQL 池”。 在“其他设置”选项卡下,找到“使用现有数据”并选择“还原点”选项。 如上面的屏幕截图所示,然后可以选择可从中还原的服务器或工作区名称。

    • 如果要还原异地备份,请选择位于源区域中的工作区,然后选择要还原的专用 SQL 池。

    注意

    不能对与现有池同名的 SQL 池执行就地还原。 无论 SQL 池位于同一工作区还是不同的工作区中。

  9. 选择“查看 + 创建” 。

通过 Azure 门户还原现有专用 SQL 池

  1. 登录到 Azure 门户

  2. 导航到要从其进行还原的专用 SQL 池。

  3. 在“概述”页的顶部,选择“还原”。

    Screenshot from the Azure portal, showing the SQL pool overview page. The Restore button is highlighted.

  4. 选择“自动还原点”或“用户定义的还原点”。

    如果专用 SQL 池没有任何自动还原点,请等待数小时或创建一个用户定义的还原点,然后再进行还原。

    如果要执行异地还原,请选择要恢复的工作区和专用 SQL 池。

  5. 选择“查看 + 创建” 。

通过 PowerShell 还原现有专用 SQL 池

  1. 打开 PowerShell 终端。

  2. 连接到 Azure 帐户,并列出与帐户关联的所有订阅。

  3. 选择包含要还原的 SQL 池的订阅。

  4. 列出专用 SQL 池的还原点。

  5. 使用 RestorePointCreationDate 选取所需的还原点。

  6. 使用 Restore-AzSynapseSqlPool PowerShell cmdlet 将专用 SQL 池还原到所需还原点。

  7. 验证已还原的专用 SQL 池是否处于联机状态。

    
    $SubscriptionName="<YourSubscriptionName>"
    $ResourceGroupName="<YourResourceGroupName>"
    $WorkspaceName="<YourWorkspaceNameWithoutURLSuffixSeeNote>"  # Without sql.azuresynapse.net
    #$TargetResourceGroupName="<YourTargetResourceGroupName>" # uncomment to restore to a different workspace.
    #$TargetWorkspaceName="<YourtargetWorkspaceNameWithoutURLSuffixSeeNote>"  
    $SQLPoolName="<YourDatabaseName>"
    $NewSQLPoolName="<YourDatabaseName>"
    
    Connect-AzAccount
    Get-AzSubscription
    Select-AzSubscription -SubscriptionName $SubscriptionName
    
    # list all restore points
    Get-AzSynapseSqlPoolRestorePoint -ResourceGroupName $ResourceGroupName -WorkspaceName $WorkspaceName -Name $SQLPoolName
    # Pick desired restore point using RestorePointCreationDate "xx/xx/xxxx xx:xx:xx xx"
    $PointInTime="<RestorePointCreationDate>"
    
    # Get the specific SQL pool to restore
    $SQLPool = Get-AzSynapseSqlPool -ResourceGroupName $ResourceGroupName -WorkspaceName $WorkspaceName -Name $SQLPoolName
    # Transform Synapse SQL pool resource ID to SQL database ID because currently the restore command only accepts the SQL database ID format.
    $DatabaseID = $SQLPool.Id -replace "Microsoft.Synapse", "Microsoft.Sql" `
        -replace "workspaces", "servers" `
        -replace "sqlPools", "databases"
    
    # Restore database from a restore point
    $RestoredDatabase = Restore-AzSynapseSqlPool –FromRestorePoint -RestorePoint $PointInTime -ResourceGroupName $SQLPool.ResourceGroupName `
        -WorkspaceName $SQLPool.WorkspaceName -TargetSqlPoolName $NewSQLPoolName –ResourceId $DatabaseID -PerformanceLevel DW100c
    
    # Use the following command to restore to a different workspace
    #$TargetResourceGroupName = $SQLPool.ResourceGroupName # for restoring to different workspace in same resourcegroup 
    #$RestoredDatabase = Restore-AzSynapseSqlPool –FromRestorePoint -RestorePoint $PointInTime -ResourceGroupName $TargetResourceGroupName `
    #    -WorkspaceName $TargetWorkspaceName -TargetSqlPoolName $NewSQLPoolName –ResourceId $DatabaseID -PerformanceLevel DW100c
    
    # Verify the status of restored database
    $RestoredDatabase.status
    

通过 PowerShell 将现有的专用 SQL 池还原到其他订阅

执行跨订阅还原时,Azure Synapse 工作区中的专用 SQL 池只能直接还原到独立的专用 SQL 池(以前称为 SQL DW)。 如果需要将 Azure Synapse 工作区中的专用 SQL 池还原到目标订阅中的工作区,则需要附加的还原步骤。

下面的 PowerShell 示例与上一个类似,但有三个主要区别:

  • 检索要还原的 SQL 池对象后,需要将订阅上下文切换到目标订阅名称。
  • 执行还原时,请使用 Az.Sql 模块而不是 Az.Synapse 模块。
  • 以下示例代码包含用于还原到目标订阅中的 Azure Synapse 工作区的附加步骤。 按照示例中所述取消注释 PowerShell 命令。

步骤:

  1. 打开 PowerShell 终端。

  2. 如果使用的是较旧版本,请使用 Update-Module 将 Az.Sql 模块更新为 3.8.0(或更高版本)。 否则,它将导致失败。 若要通过 PowerShell 验证你的版本,请执行以下操作:

    foreach ($i in (get-module -ListAvailable | ?{$_.name -eq 'az.sql'}).Version) { $version = [string]$i.Major + "." + [string]$i.Minor; if ($version -gt 3.7) {write-host "Az.Sql version $version installed. Prequisite met."} else {update-module az.sql} }
    
  3. 连接到 Azure 帐户,并列出与帐户关联的所有订阅。

  4. 选择包含要还原的 SQL 池的订阅。

  5. 列出专用 SQL 池的还原点。

  6. 使用 RestorePointCreationDate 选取所需的还原点。

  7. 选择应在其中还原 SQL 池的目标订阅。

  8. 使用 Restore-AzSqlDatabase PowerShell cmdlet 将专用 SQL 池还原到所需还原点。

  9. 验证已还原的专用 SQL 池(之前称为 SQL DW)是否处于联机状态。

  10. 如果所需目标为 Synapse 工作区,请通过取消注释代码来执行其他还原步骤。

    1. 为新创建的数据仓库创建还原点。

    2. 使用 Select -Last 1 语法检索创建的最后一个还原点。

    3. 执行到所需 Azure Synapse 工作区的还原。

      $SourceSubscriptionName="<YourSubscriptionName>"
      $SourceResourceGroupName="<YourResourceGroupName>"
      $SourceWorkspaceName="<YourServerNameWithoutURLSuffixSeeNote>"  # Without sql.azuresynapse.net
      $SourceSQLPoolName="<YourDatabaseName>"
      $TargetSubscriptionName="<YourTargetSubscriptionName>"
      $TargetResourceGroupName="<YourTargetResourceGroupName>"
      $TargetServerName="<YourTargetServerNameWithoutURLSuffixSeeNote>"  # Without sql.azuresynapse.net
      $TargetDatabaseName="<YourDatabaseName>"
      #$TargetWorkspaceName="<YourTargetWorkspaceName>" # uncomment if restore to an Azure Synapse workspace is required
      
      # Update Az.Sql module to the latest version (3.8.0 or above)
      # Update-Module -Name Az.Sql -RequiredVersion 3.8.0
      
      Connect-AzAccount
      Get-AzSubscription
      Select-AzSubscription -SubscriptionName $SourceSubscriptionName
      
      # list all restore points
      Get-AzSynapseSqlPoolRestorePoint -ResourceGroupName $SourceResourceGroupName -WorkspaceName $SourceWorkspaceName -Name $SourceSQLPoolName
      # Pick desired restore point using RestorePointCreationDate "xx/xx/xxxx xx:xx:xx xx"
      $PointInTime="<RestorePointCreationDate>"
      
      # Get the specific SQL pool to restore
      $SQLPool = Get-AzSynapseSqlPool -ResourceGroupName $SourceResourceGroupName -WorkspaceName $SourceWorkspaceName -Name $SourceSQLPoolName
      # Transform Synapse SQL pool resource ID to SQL database ID because currently the restore command only accepts the SQL database ID format.
      $DatabaseID = $SQLPool.Id -replace "Microsoft.Synapse", "Microsoft.Sql" `
          -replace "workspaces", "servers" `
          -replace "sqlPools", "databases"
      
      # Switch context to the destination subscription
      Select-AzSubscription -SubscriptionName $TargetSubscriptionName
      
      # Restore database from a desired restore point of the source database to the target server in the desired subscription
      $RestoredDatabase = Restore-AzSqlDatabase –FromPointInTimeBackup –PointInTime $PointInTime -ResourceGroupName $TargetResourceGroupName `
          -ServerName $TargetServerName -TargetDatabaseName $TargetDatabaseName –ResourceId $DatabaseID
      
      # Verify the status of restored database
      $RestoredDatabase.status
      
      # uncomment below cmdlets to perform one more restore to push the SQL Pool to an existing workspace in the destination subscription
      # # Create restore point
      # New-AzSqlDatabaseRestorePoint -ResourceGroupName $RestoredDatabase.ResourceGroupName -ServerName $RestoredDatabase.ServerName `
      #     -DatabaseName $RestoredDatabase.DatabaseName -RestorePointLabel "UD-001"
      # # Gets the last restore point of the sql dw (will use the RestorePointCreationDate property)
      # $RestorePoint = Get-AzSqlDatabaseRestorePoint -ResourceGroupName $RestoredDatabase.ResourceGroupName -ServerName $RestoredDatabase.ServerName `
      #     -DatabaseName $RestoredDatabase.DatabaseName | Select -Last 1
      # # Restore to destination synapse workspace
      # $FinalRestore = Restore-AzSynapseSqlPool –FromRestorePoint -RestorePoint $RestorePoint.RestorePointCreationDate -ResourceGroupName $TargetResourceGroupName `
      #     -WorkspaceName $TargetWorkspaceName -TargetSqlPoolName $TargetDatabaseName –ResourceId $RestoredDatabase.ResourceID -PerformanceLevel DW100c
      
      

疑难解答

还原操作可能会导致基于“RequestTimeout”异常的部署失败。

Screenshot from resource group deployments dialog of a timeout exception.

可以忽略此超时。 请查看 Azure 门户中的“专用 SQL 池”页,它可能仍然是“正在还原”状态,最终将会转换为“联机”。

Screenshot of SQL pool dialog with the status that shows restoring.