還原現有的專用 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 集區還原至所需的還原點。

    • 若要將專用 SQL 集區還原至不同的工作區,請務必指定其他工作區名稱。 此工作區也可以位於不同的資源群組和區域中。
    • 若要還原至不同的訂用帳戶,請參閱 本文稍後透過PowerShell 將現有的專用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. 如果使用 舊版,請將 Az.Sql 模組更新為 3.8.0(或更新版本 Update-Module)。 否則,它會導致失敗。 若要透過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.