How to restore a deleted Azure Web App

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
Get-AzDeletedWebApp output

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 command:

Restore-AzDeletedWebApp -ResourceGroupName SwapTestRG -Name undeletesiteexample -TargetAppServicePlanName SwapTestASP
Restore-AzDeletedWebApp output

Or alternatively you can pipe the output of the Get-AzDeletedWebApp command:

$deletedSiteInfo = Get-AzDeletedWebApp -Name undeletesiteexample
$deletedSiteInfo | Restore-AzDeletedWebApp -ResourceGroupName SwapTestRG -Name undeletesiteexample -TargetAppServicePlanName SwapTestASP

The 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.

Leave a Reply

Your email address will not be published. Required fields are marked *