【Azure App Service】误删除App Service资源,怎么办?

发布时间 2023-12-12 20:20:26作者: 路边两盏灯

问题描述

操作不当,误删除了App Service的资源,怎么办?

 

问题解答

根据Azure 官方文档,可以使用 Powershell 命令恢复到原始 App Service 应用名称。

操作步骤

第一步:列出已删除的应用

Get-AzDeletedWebApp  
Get-AzDeletedWebApp  |Format-Table -Property DeletionTime,Name,Location,ResourceGroupName,SubscriptionId, Id,DeletedSiteId
Get-AzDeletedWebApp -Name <your web app name> |Format-Table -Property DeletionTime,Name,Location,ResourceGroupName,SubscriptionId, Id,DeletedSiteId 

执行截图:

  

第二步:还原已删除的应用

Restore-AzDeletedWebApp -ResourceGroupName <original_rg> -Name <original_app> -TargetResourceGroupName <target_rg> -TargetName <target_app> -TargetAppServicePlanName <target_asp>

执行截图:

 

完整的PowerShell脚本为:
 Connect-AzAccount -Environment AzureChinaCloud
  
 Select-AzSubscription -Subscription 'your subscription id'

 Restore-AzDeletedWebApp -TargetResourceGroupName <my_rg> -Name <my_app> -TargetAppServicePlanName <my_asp>

 Restore-AzDeletedWebApp -ResourceGroupName <original_rg> -Name <original_app> -TargetResourceGroupName <target_rg> -TargetName <target_app> -TargetAppServicePlanName <target_asp>

 

参考资料

Install Azure PowerShell on Windows : https://learn.microsoft.com/en-us/powershell/azure/install-azps-windows?view=azps-11.1.0&tabs=powershell&pivots=windows-psgallery 

使用 PowerShell 还原已删除的应用服务应用:https://learn.microsoft.com/zh-cn/azure/app-service/app-service-undelete