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

Tip

Microsoft Fabric Data Warehouse 是一個企業規模的關聯式倉庫,建立在資料湖基礎上,具備未來準備架構、內建 AI 及新功能。 如果你是資料倉儲新手,建議先從Fabric Data Warehouse開始。 現有的 專用 SQL 工作負載可升級至 Fabric,以取得資料科學、即時分析與報告等多項新功能。

在本文中,您將了解如何在使用 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
    

疑難排解

錯誤:「在處理請求時發生了意外錯誤。」

若收到此訊息,原始資料庫可能因原始工作空間壽命短暫而無法恢復任何可恢復點。 通常是在工作區存在時間不到一小時的情況下,才會發生此問題。

錯誤:「ValidationFailed:所提供的資源 ID 對此操作無效。 請使用 SQL 池資源。」

如果收到此錯誤,請確認該 ID sourceDatabaseId 是否使用支援的資源 ID 格式,並識別指定的專用來源 SQL 池。

支援的格式

Synapse SQL 集區資源 ID /subscriptions/{subscriptionId}/resourceGroups/{workspaceResourceGroup}/providers/Microsoft.Synapse/workspaces/{workspaceName}/sqlPools/{sqlPoolName}

受控 SQL Database 資源 ID /subscriptions/{subscriptionId}/resourceGroups/{managedResourceGroup}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}