OMG — Deleted My Web App and App Service Plan, Whats Next ?

As a human being we all can do mistakes. There for we can delete production grade Azure Web App accidentally. Sometimes this scenarios can be happen when hacker penetrate the Azure subscription credentials and get control, and intentionally delete production Web App.

So whats happen now. What if we want to recover it quickly. Earlier we need to submit a support ticket to Azure to restore Azure Web App and it take hours if you don’t have premier support. But introduction of Azure App Service Web App Undelete we can restore the app without any support plan.

YES you can imagine how cool it was right. Lets see how we can do it.

Deleted Web apps are stored in Subscription base so if you have multiple subscription first we need to select right subscription for that we can use following Azure PowerShell commands

#Login to Azure PowerShell
Login-AzureRmAccount
#Select Azure Subscription
Select-AzureRmSubscription -Subscription "<SubName>"

Make sure you have the latest version of Azure Powershell Module AzureRM.Websites 5.1.0

#Get Azure RM Powershell Module Version
Get-Module -Name AzureRM.Websites
#Get Latest PowerShell Module
Install-Module -Name AzureRM.Websites -RequiredVersion 5.1.0

Before this demo I created a Web app and deleted from my Resource Group name DeleteWebapp. So lets see the deleted Web App (Times are in UTC)

#Get Deleted Web App
Get-AzureRmDeletedWebApp -ResourceGroupName DeleteWebapp

Next I’ll create PS variable to store the deleted app details

#Store As a Variable
$deletedApp= Get-AzureRmDeletedWebApp -ResourceGroupName DeleteWebapp

We will create a new Resource group to restore this app, then create an App Service Plan to restore the deleted app. NOTE — Make Sure the App service Plan is Basic or higher tire restoring feature is not supported for free tier

#Create new Resource Group for Web App restore 
New-AzureRmResourceGroup -Name WebAppRestore -Location "Central US"
#Create an App Service Plan 
New-AzureRmAppServicePlan -Location "Central US" -Tier Standard -Name WebAppRestoreAppPlan -ResourceGroupName WebAppRestore

Lets restore deleted web app to the newly created App Service plan. For that previous step we sore the details of the deleted web app as a variable, we can use that variable to restore the web app.

#restore the web App
$deletedApp | Restore-AzureRmDeletedWebApp -TargetResourceGroupName WebAppRestore -TargetAppServicePlanName WebAppRestoreAppPlan

If you have done this correctly you can see that the web app state is running at shell and portal we can see the app running

NOTE — We can restore deleted web apps up to 30 days from deletion date, and its compliant with GDPR. As per the GDPR it can’t keep customer data more than 30 days