使用 PowerShell 还原已删除的应用服务应用Restore deleted App Service app Using PowerShell

如果意外删除了 Azure 应用服务中的应用,则可以使用 Az PowerShell 模块中的命令将其还原。If you happened to accidentally delete your app in Azure App Service, you can restore it using the commands from the Az PowerShell module.

备注

  • 初始删除 30 天后,已删除的应用将从系统中清除。Deleted apps are purged from the system 30 days after the initial deletion. 清除应用后,将无法恢复它。After an app is purged, it can't be recovered.
  • 消耗计划不支持撤消删除功能。Undelete functionality isn't supported for the Consumption plan.
  • 在应用服务环境中运行的应用服务应用不支持快照。Apps Service apps running in an App Service Environment don't support snapshots. 因此,应用服务环境中运行的应用服务应用不支持撤消删除功能和克隆功能。Therefore, undelete functionality and clone functionality aren't supported for App Service apps running in an App Service Environment.

重新注册应用服务资源提供程序Re-register App Service resource provider

有些客户可能会遇到这样的问题:检索已删除的应用的列表时失败。Some customers might come across an issue where retrieving the list of deleted apps fails. 若要解决该问题,请运行以下命令:To resolve the issue, run the following command:

 Register-AzResourceProvider -ProviderNamespace "Microsoft.Web"

列出已删除的应用List deleted apps

若要获取已删除的应用集合,可以使用 Get-AzDeletedWebAppTo get the collection of deleted apps, you can use Get-AzDeletedWebApp.

若要获取有关特定的已删除应用的详细信息,可以使用:For details on a specific deleted app you can use:

Get-AzDeletedWebApp -Name <your_deleted_app> -Location <your_deleted_app_location> 

详细信息包括:The detailed information includes:

  • DeletedSiteId:应用的唯一标识符,适用于删除了多个同名应用的情况DeletedSiteId: Unique identifier for the app, used for scenarios where multiple apps with the same name have been deleted
  • SubscriptionID:包含已删除的资源的订阅SubscriptionID: Subscription containing the deleted resource
  • 位置:原始应用的位置Location: Location of the original app
  • ResourceGroupName:原始资源组的名称ResourceGroupName: Name of the original resource group
  • 名称:原始应用的名称。Name: Name of the original app.
  • Slot:槽的名称。Slot: the name of the slot.
  • Deletion Time:删除应用的时间Deletion Time: When was the app deleted

还原已删除的应用Restore deleted app

备注

函数应用不支持 Restore-AzDeletedWebAppRestore-AzDeletedWebApp isn't supported for function apps.

确定要还原的应用后,可使用 Restore-AzDeletedWebApp 进行还原。Once the app you want to restore has been identified, you can restore it using Restore-AzDeletedWebApp.

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

备注

部署槽不会作为应用的一部分进行还原。Deployment slots are not restored as part of your app. 如果需要还原过渡槽,请使用 -Slot <slot-name> 标志。If you need to restore a staging slot, use the -Slot <slot-name> flag.

命令的输入包括:The inputs for command are:

  • 目标资源组:要将应用还原到的目标资源组Target Resource Group: Target resource group where the app will be restored
  • 名称:应用的名称,应全局唯一。Name: Name for the app, should be globally unique.
  • TargetAppServicePlanName:链接到该应用的应用服务计划TargetAppServicePlanName: App Service plan linked to the app

默认情况下,Restore-AzDeletedWebApp 会同时还原应用配置以及任何内容。By default Restore-AzDeletedWebApp will restore both your app configuration as well any content. 如果只想还原内容,请在此 cmdlet 中使用 -RestoreContentOnly 标志。If you want to only restore content, you use the -RestoreContentOnly flag with this commandlet.

备注

如果应用以前托管在应用服务环境中,然后被删除,则还原该应用的前提是相应的应用服务环境仍然存在。If the app was hosted on and then deleted from an App Service Environment, it can be restored only if the corresponding App Service Environment still exists.

可在以下文章中找到完整的 cmdlet 参考信息:Restore-AzDeletedWebAppYou can find the full commandlet reference here: Restore-AzDeletedWebApp.