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.

Configure a Backup for your Azure App Service

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.

Configure a Backup for your Azure App Service

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\wwwroot folder 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.

Configure a Backup for your Azure App Service

Pause
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: https://docs.microsoft.com/en-us/azure/app-service/scripts/powershell-backup-scheduled#sample-scripthttps://microsoft.github.io/AzureTipsAndTricks/blog/tip28.html

This blog is part of Azure Week. Check it out for more great content!

About the Author:

I, Ashish Sharma, am a Cloud Operations Engineer based in India. I have a Bachelor degree in Computer Science from APJ Abdul Kalam University. 
I have a total 5 years of experience in Cloud Computing with certification in Kubernetes and Azure.  I started writing blogs in 2018 and since then actively contributing to my community by giving free consultations and guidance. 
Besides writing I love soccer, running marathons, hiking and travelling. I have a beautiful wife who helps me to keep up my motivation. My aim is to share my technical knowledge in the simplest way and keep myself updated at all times.

Reference:

Sharma, A. (2021). Configure a Backup for your Azure App Service. Available at: https://www.iamashishsharma.com/2021/01/configure-backup-for-your-azure-app.html [Accessed: 9th July 2021].

Share this on...

Rate this Post:

Share:

Topics:

Azure

Tags: