从已删除的工作区还原专用 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. 指定删除工作区的近似日期/时间。

  5. 为要从已删除的工作区恢复的数据库构造资源 ID。

  6. 从已删除的工作区还原数据库

  7. 验证已恢复数据库的状态是否为“联机”。

$SubscriptionID="<YourSubscriptionID>"
$ResourceGroupName="<YourResourceGroupName>"
$WorkspaceName="<YourWorkspaceNameWithoutURLSuffixSeeNote>"  # Without sql.azuresynapse.azure.cn
$DatabaseName="<YourDatabaseName>"
$TargetResourceGroupName="<YourTargetResourceGroupName>" 
$TargetWorkspaceName="<YourtargetServerNameWithoutURLSuffixSeeNote>"  
$TargetDatabaseName="<YourDatabaseName>"

Connect-AzAccount -Environment AzureChinaCloud
Set-AzContext -SubscriptionID $SubscriptionID

# Define the approximate point in time the workspace was dropped as DroppedDateTime "yyyy-MM-ddThh:mm:ssZ" (ex. 2022-01-01T16:15:00Z)
$PointInTime="<DroppedDateTime>" 
$DroppedDateTime = Get-Date -Date $PointInTime 


# construct the resource ID of the sql pool you wish to recover. The format required 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.
$RestoredDatabase = Restore-AzSynapseSqlPool -FromDroppedSqlPool -DeletionDate $DroppedDateTime -TargetSqlPoolName $TargetDatabaseName -ResourceGroupName $TargetResourceGroupName -WorkspaceName $TargetWorkspaceName -ResourceId $SourceDatabaseID

# Verify the status of restored database
$RestoredDatabase.status

疑难解答

如果收到“处理请求时出现意外错误”消息,则表明原始工作区可能因存续期较短而没有任何可用的恢复点。 通常,如果工作区存在不到一小时,则会发生这种情况。