本文介绍如何在使用 PowerShell 意外删除服务器后在 Azure Synapse Analytics 中还原专用 SQL 池(以前为 SQL DW)。
备注
建议使用 Azure Az PowerShell 模块与 Azure 交互。 请参阅安装 Azure PowerShell 以开始使用。 若要了解如何迁移到 Az PowerShell 模块,请参阅 将 Azure PowerShell 从 AzureRM 迁移到 Az。
打开 PowerShell。
连接到 Azure 帐户。
将上下文设置为包含已删除服务器的订阅。
指定删除服务器的大致日期时间。
为要从已删除的服务器恢复的数据库构造资源 ID。
从已删除的服务器还原数据库
验证已恢复数据库的状态是否为“联机”。
$SubscriptionID="<YourSubscriptionID>"
$ResourceGroupName="<YourResourceGroupName>"
$ServerName="<YourServerNameWithoutURLSuffixSeeNote>" # Without database.chinacloudapi.cn
$DatabaseName="<YourDatabaseName>"
$TargetServerName="<YourtargetServerNameWithoutURLSuffixSeeNote>"
$TargetDatabaseName="<YourDatabaseName>"
Connect-AzAccount -Environment AzureChinaCloud
Set-AzContext -SubscriptionId $SubscriptionID
# Define the approximate point in time the server 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 database 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/"+$ServerName+"/restorableDroppedDatabases/"+$DatabaseName+","+$DroppedDateTime.ToUniversalTime().ToFileTimeUtc().ToString()
# Restore to target workspace with the source database.
$RestoredDatabase = Restore-AzSqlDatabase -FromDeletedDatabaseBackup -DeletionDate $DroppedDateTime -ResourceGroupName $ResourceGroupName -ServerName $TargetServerName -TargetDatabaseName $TargetDatabaseName -ResourceId $SourceDatabaseID
# Verify the status of restored database
$RestoredDatabase.status
如果收到“处理请求时发生意外错误。”消息,则原始数据库可能由于原始服务器生存期较短而没有可用的恢复点。 通常,这是指服务器存在时间不足一小时的情况。