Restore(Undelete) Deleted Web Apps
Published Nov 03 2021 09:38 AM 24.3K Views
Microsoft

We can restore a delete web app,

  • If the WebApp was deleted in last 30 days.
  • If the WebApp was not hosted on Free or Shared sku.
  • If the WebApp was not hosted on App Service Environment (ASE).
  • If it's not a Function App hosted on Consumption or Elastic Premium plans.

Steps to restore a deleted Web App

We can restore deleted webapp using powershell (Restore deleted apps - Azure App Service | Microsoft Docs) or Azure CLI (az webapp deleted | Microsoft Docs). In the steps below, I have used PowerShell cmdlets in Cloud shell:

 

amolmehrotra_0-1635956589189.png

  • If we are not aware of deleted app details, then we can run Get-AzDeletedWebApp to get a list of deleted apps

         PS /home/amol> Get-AzDeletedWebApp

 

amolmehrotra_1-1635956589192.png

 

  • If we are aware of the delete app resource group and name, then we can specify that in the following attributes:

         PS /home/amol> Get-AzDeletedWebApp -ResourceGroupName "LabDemo" -Name "labsampledemo"

 

  • To make is easier to restore, we can load the webapp details into a variable

         PS /home/amol> $deletedSites = Get-AzDeletedWebApp -ResourceGroupName "LabDemo" -Name "labsampledemo"

         PS /home/amol> write-output $deletedSites[0]

 

amolmehrotra_2-1635956589194.png

 

  • Then use Restore-AzDeletedWebApp cmdlet to restore the delete app into a new app. You may choose the same name or a different name.

 PS /home/amol> Restore-AzDeletedWebApp -TargetResourceGroupName "LabDemo" -TargetName "labsampledemo" -           TargetAppServicePlan "LabSampleDemo" -InputObject $deletedSites[0]

 

amolmehrotra_3-1635956589196.png

Note: For debugging PowerShell or Azure CLI errors, -Debug could be used for a detailed error message. 

 

Important: It is advisable to always check the type of deleted app that you are trying to restore. Make sure that the new app that you have created where you would like to restore the deleted app is of the same type. Else you will get an error.

 

The below given Azure CLI command, could be used to validate the type\kind of deleted app. Look the value of kindPropertiesKind attribute in the result. 

 

az webapp deleted list --name <name of deleted site>

 

 

Multiple delete versions available

 

We could come across scenarios where we have multiple versions of the deleted app. This could happen when the same app was deleted and restored multiple times with same name.

When we run Get-AzDeletedWebApp, we can differentiate among various versions by looking at DeletionTime property.

 

PS /home/amol> Get-AzDeletedWebApp -ResourceGroupName "LabDemo" -Name "labsampledemo"

 

amolmehrotra_4-1635956589204.png

 

If we simply use restore -name -resource group in Get-AzDeletedWebApp cmdlet, then it would restore the most recently deleted site version.

If we want to pick one of the older versions, loading the webapp details into a variable helps.

This way we can pick any one the items from the array.

 

PS /home/amol> $deletedSites = Get-AzDeletedWebApp -ResourceGroupName "LabDemo" -Name "labsampledemo"

 

amolmehrotra_5-1635956589205.png

 

PS /home/amol> Restore-AzDeletedWebApp -TargetResourceGroupName "LabDemo" -TargetName "labsampledemo" -TargetAppServicePlan "LabSampleDemo" -InputObject $deletedSites[0]

 

amolmehrotra_6-1635956589198.png

 

Curious case of Undeleting Function Apps

If we are not sure if the deleted app was FunctionApp, we can verify that using this Azure CLI command, and check the value of kindPropertiesKind attribute in the result. For webapp, value of this attribute will be "app" and for Function App it would be "functionapp".

 

az webapp deleted list --name <name of deleted site>

 

If the Function App was hosted on Dedicated hosting plan, then we have a way to restore it.

 

  1. Create a new function App.
  2. Fetch the deleted site Id using Get-AzDeletedWebApp cmdlet
  3. Restore to the newly created function app using this cmdlet:

Restore-AzDeletedWebApp -ResourceGroupName <RGofnewapp> -Name <newApp> -deletedId "/subscriptions/xxxx/providers/Microsoft.Web/locations/xxxx/deletedSites/xxxx"

 

Currently there is no support for Undelete (Restore-AzDeletedWebApp) Function Apps that are hosted on Consumption plan or Elastic premium plan. These are the scenarios where content resides on Azure Files. If you have not 'hard' deleted the azure files storage account or if it exists and has not been deleted, then you may the steps below as workaround:

 

  • Create a new function app
  • Set the following app settings for the app content.

 


    "name": "AzureWebJobsStorage",
    "value": "<Connection String for storage account of deleted site>",
    "slotSetting": false
},                 
{
     "name": "WEBSITE_CONTENTAZUREFILECONNECTIONSTRING",
     "value": "<Connection String for storage account of deleted site>",
     "slotSetting": false
},
{
     "name": "WEBSITE_CONTENTSHARE",
     "value": "<storage account file share> ",    
     "slotSetting": false
}

 

Alternatively, if you have the function app content,

  • Create a zip file with contents from wwwroot folder.
  • Create a new function app.
  • Open Kudu portal of the new function app.
  • Open Debug console --> Site --> wwwroot
  • Drag and drop the zip file we created in step 1 from the function app content.

 

Co-Authors
Version history
Last update:
‎Jan 04 2022 04:43 AM
Updated by: