If you happened to accidentally delete your web app in Azure App Service then up until recently you had to open a support case in order to get it restored. But now you can restore it yourself by using the commands from the Az PowerShell module. This blog post explains how to do that.
Assume you used to have a site named “undeletesiteexample” and you have deleted it accidentally. The first step to recover it is to get the details of the deleted app:
Get-AzDeletedWebApp -Name undeletesiteexample
This command will return the information about the deleted app such as when it was deleted and what is its DeletedSiteId. The DeletedSiteId is used to uniquely identify the deleted app in case there have been several apps with the same name deleted.
The next step is to restore the deleted app by using
Restore-AzDeletedWebApp -ResourceGroupName SwapTestRG -Name undeletesiteexample -TargetAppServicePlanName SwapTestASP
Or alternatively you can pipe the output of the
$deletedSiteInfo = Get-AzDeletedWebApp -Name undeletesiteexample $deletedSiteInfo | Restore-AzDeletedWebApp -ResourceGroupName SwapTestRG -Name undeletesiteexample -TargetAppServicePlanName SwapTestASP
Restore-AzDeletedWebApp can be used to restore a site using the same or different name. Also you can chose where to restore it to, e.g. which resource group, app service plan or deployment slot. In addition you can also chose to restore just the content (
[-RestoreContentOnly]) or the content and the site’s configuration settings.
Note that if the app was hosted on and then deleted from an App Service Environment then it can be restored only if the corresponding App Service Environment still exist.