從已刪除的工作區還原專用 SQL 集區

在本文中,您將了解如何在使用 PowerShell 意外卸除工作區之後,在 Azure Synapse Analytics 中還原專用 SQL 集區。

注意

本指南僅適用於 Azure Synapse 工作區中的專用 SQL 集區。 若是獨立的專用 SQL 集區 (先前稱為 SQL DW),請遵循從已刪除的伺服器還原 sql 集區指南。

開始之前

注意

建議您使用 Azure Az PowerShell 模組來與 Azure 互動。 若要開始使用,請參閱安裝 Azure PowerShell (部分機器翻譯)。 若要了解如何移轉至 Az PowerShell 模組,請參閱將 Azure PowerShell 從 AzureRM 移轉至 Az

從卸除的工作區還原 SQL 集區

下列範例指令碼會完成這些步驟:

  1. 開啟 PowerShell

  2. 連線至您的 Azure 帳戶。

  3. 將內容設定為含有已卸除工作區的訂用帳戶。

  4. 判斷卸除工作區的日期時間。 此步驟會擷取卸除工作區 SQL 集區的確切日期和時間。

    • 此步驟假設仍可使用具有相同名稱資源群組和相同值的工作區。
    • 如果無法使用,請使用相同的工作區名稱、資源群組名稱、區域,以及先前卸除的工作區中所有相同的值,重新建立已卸除的工作區。
  5. 建構一個字串,作為您想復原之 sql 集區的資源識別碼。 格式需要 Microsoft.Sql。 這包括卸除伺服器的日期和時間。

  6. 從已卸除的工作區還原資料庫。 使用來源 SQL 集區還原至目標工作區。

  7. 確認已復原資料庫的狀態為「連線」。

    $SubscriptionID = "<YourSubscriptionID>"
    $ResourceGroupName = "<YourResourceGroupName>"
    $WorkspaceName = "<YourWorkspaceNameWithoutURLSuffixSeeNote>"  # Without sql.azuresynapse.net
    $DatabaseName = "<YourDatabaseName>"
    $TargetResourceGroupName = "<YourTargetResourceGroupName>"
    $TargetWorkspaceName = "<YourtargetServerNameWithoutURLSuffixSeeNote>"
    $TargetDatabaseName = "<YourDatabaseName>"
    
    Connect-AzAccount
    Set-AzContext -SubscriptionID $SubscriptionID
    
    # Get the exact date and time the workspace SQL pool was dropped.
    # This assumes that the workspace with the same name resource group and same values is still available.
    # If not, recreate the dropped workspace with the same workspace name, resource group name, region, 
    # and all the same values from prior dropped workspace.
    # There should only be one selection to select from.
    $paramsGetDroppedSqlPool = @{
        ResourceGroupName = $ResourceGroupName
        WorkspaceName     = $WorkspaceName
        Name              = $DatabaseName
    }
    $DroppedDateTime = Get-AzSynapseDroppedSqlPool @paramsGetDroppedSqlPool `
        | Select-Object -ExpandProperty DeletionDate
    
    # Construct a string of the resource ID of the sql pool you wish to recover.
    # The format requires Microsoft.Sql. This includes the approximate date time the server was dropped.
    $SourceDatabaseID = "/subscriptions/$SubscriptionID/resourceGroups/$ResourceGroupName/providers/" `
                    + "Microsoft.Sql/servers/$WorkspaceName/databases/$DatabaseName"    
    
    # Restore to the target workspace with the source SQL pool.
    $paramsRestoreSqlPool = @{
        FromDroppedSqlPool  = $true
        DeletionDate        = $DroppedDateTime
        TargetSqlPoolName   = $TargetDatabaseName
        ResourceGroupName   = $TargetResourceGroupName
        WorkspaceName       = $TargetWorkspaceName
        ResourceId          = $SourceDatabaseID
    }
    $RestoredDatabase = Restore-AzSynapseSqlPool @paramsRestoreSqlPool
    
    # Verify the status of restored database
    $RestoredDatabase.status
    

疑難排解

如果收到「處理要求時發生未預期的錯誤」訊息,則原始資料庫可能因原始工作區效期過短而沒有可用的復原點。 通常是在工作區存在時間不到一小時的情況下,才會發生此問題。