Azure App Service Backup Failure Alert

The Backup feature in Azure App Service allows us to easily create app backups manually or on a schedule. Refer this blog to know more about how to configure backup in Azure Web App:

https://www.iamashishsharma.com/2021/01/configure-backup-for-your-azure-app.html

In this article, we will discuss how to create an alert which will get triggered whenever backup of web app will fail.

Go to Alerts and create new alert rule.

Select your Azure web app for which you want to configure backup failure alert.

Click on Condition and Search “Create Web App Backup”.

Then change the Status to “Failed” and click on “Done”.

This will create a condition which will trigger whenever any backup will fail in Azure Web App.

Click on Action Groups and then you can select a existing action group. Otherwise click on Create action group.

Select your subscription and resource group. Enter your action group name.

Select your Notification method. I have added Email in the notification type as shown below. You can also add Webhook etc from Actions tabs.

 

Then click on review and create.

Enter your alert rule details such as alert name ,description and save alert to your resource group.

Click on Create alert rule.

This will create an alert rule which will get triggered whenever Azure web app backup will fail.

Configure a Backup for your Azure App Service

The Backup feature in Azure App Service allows us to easily create app backups manually or on a schedule. You can restore the app to a snapshot of a previous state by overwriting the existing app or restoring to another app.

Refer the below steps to schedule your backup:

1. Go to your App service and click on Backups from left Navigation bar.

2. Click on Configure and select your Azure storage account and container to store your backup. Then configure the schedule to start your backup as illustrated below.

3. Once everything is configured you can see backup status as shown below.

4. Once backup is succeeded, you can see the next scheduled backup details.

Exclude files from your backup

If you want to exclude few folders and files from being stored in your backup, then you can create _backup.filter file inside D:\\home\\site\\wwwrootfolder of your web app.

Let’s assume you want to exclude Logs folder and ashish.pdf file.

Then create _backup.filter file and add file & folder details inside the file as shown below.

Now, any files and folders that are specified in _backup.filter is excluded from the future backups scheduled or manually initiated.

Configure Azure web app backup using Powershell:

Refer the below powershell sample:
  
$webappname=\"mywebapp$(Get-Random -Minimum 100000 -Maximum 999999)\"
$storagename=\"$($webappname)storage\"
$container=\"appbackup\"
$location=\"West Europe\"

# Create a resource group.
New-AzResourceGroup -Name myResourceGroup -Location $location

# Create a storage account.
$storage = New-AzStorageAccount -ResourceGroupName myResourceGroup `
-Name $storagename -SkuName Standard_LRS -Location $location

# Create a storage container.
New-AzStorageContainer -Name $container -Context $storage.Context

# Generates an SAS token for the storage container, valid for 1 year.
# NOTE: You can use the same SAS token to make backups in Web Apps until -ExpiryTime
$sasUrl = New-AzStorageContainerSASToken -Name $container -Permission rwdl `
-Context $storage.Context -ExpiryTime (Get-Date).AddYears(1) -FullUri

# Create an App Service plan in Standard tier. Standard tier allows one backup per day.
New-AzAppServicePlan -ResourceGroupName myResourceGroup -Name $webappname `
-Location $location -Tier Standard

# Create a web app.
New-AzWebApp -ResourceGroupName myResourceGroup -Name $webappname `
-Location $location -AppServicePlan $webappname

# Schedule a backup every day, beginning in one hour, and retain for 10 days
Edit-AzWebAppBackupConfiguration -ResourceGroupName myResourceGroup -Name $webappname `
-StorageAccountUrl $sasUrl -FrequencyInterval 1 -FrequencyUnit Day -KeepAtLeastOneBackup `
-StartTime (Get-Date).AddHours(1) -RetentionPeriodInDays 10

# List statuses of all backups that are complete or currently executing.
Get-AzWebAppBackupList -ResourceGroupName myResourceGroup -Name $webappname

References: 

Restore a deleted Azure Web App

If you have accidently deleted your Azure Web App and looking to restore it, then refer the below steps to restore your Azure Web App.

1. Run the below Powershell to get the details of deleted web app.

Get-AzDeletedWebApp -Name <>

2. Restore the web app.

Restore-AzDeletedWebApp -ResourceGroupName <> -Name <> -TargetAppServicePlanName <>

 

You can also check Activity logs of restored web apps as illustrated below.

Note:

1. Deleted apps are purged from the system 30 days after the initial deletion. After an app is purged, it can\’t be recovered.

2. Undelete functionality isn\’t supported for the Consumption plan.

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

References: https://docs.microsoft.com/en-us/azure/app-service/app-service-undelete