Backing Up Azure App Service

Last Update: Sep 04, 2024 | Published: Jan 29, 2018

SHARE ARTICLE

backup hero img
In this post, I will show you how to backup Web apps that are hosted as an Azure App Service in an App Service Plan.
 

 

Protect the Service

An App Service or Web app might run in PaaS but your requirements to protect it are probably no different than they would be if it was running in a virtual machine. This is why it is possible, using the Standard and Premium App Service Plan tiers only, to backup your Web apps. The following kinds of data can be protected:

  • Web app content
  • Settings
  • Any connected (connection string in the settings) databases

Note that the following database types are supported:

  • Azure SQL
  • Azure Database for MySQL
  • Azure Database for PostgreSQL
  • MySQL in-app (also an App Service)

There are three requirements to back up a web app:

  • The web app must be running on a Standard or Premium tier App Service Plan.
  • You will need a storage account to store the backups (Blob storage).
  • The entire backup must be no bigger than 10GB, including the web app content, settings, and database content.

Enabling Backups

The first step for enabling backups is to create a storage account. If you want to use blob tiering (this would require a bit of effort), then you could use a General Purpose v2 (GPv2) storage account. However, if you do not need blob tiering, I would recommend a General Purpose v1 (GPv1) storage account because of the much lower storage transaction charges (often almost unnoticeable in the bill).
With the storage account ready, you can configure backs up in the web app or App Service. Open the App Service that you want to protect in the Azure Portal and browse to Settings > Backups. Click Configure and a Backup Configuration blade should appear:

  1. Select the storage account.
  2. Click + to create a private container. I would name this container after the web app or App Service.
  3. Select the container.
  4. If you want to schedule backups, then set Scheduled Backup to On and configure a schedule. Fairly static sites might be backed up less frequently.
  5. Select your retention. Note that 0 means never delete backups.
  6. Decide if at least one backup should always be retained.
  7. Choose if any connected databases should be included in the web app backup.
  8. Click Save to finalize the backup configuration.

Configuring an Azure App Service or web app backup [Image Credit: Aidan Finn]
Configuring an Azure App Service or Web App Backup [Image Credit: Aidan Finn]
 
It will take a few minutes for the backup to be configured. After that, any scheduled backups will run automatically but you also have the option to run a manual backup.

Running a Manual Backup

You can return to Settings > Backup in the web app to see the status of backups. You also can click the Backup button to manually trigger a backup.

An Azure App Service or web app backup in progress [Image Credit: Aidan Finn]
An Azure App Service or Web App Backup in Progress [Image Credit: Aidan Finn]

The Backup Storage

You can see the backup data in the storage account. Open the storage account in the Azure Portal or a tool, such as Azure Storage Explorer and browse to Blobs. Then go into the container (folder) that you created to store the web app’s backups in.
Here you will see three files that contain time stamps in their names:

  • Log file: A record of the backup operation.
  • XML file: A description of the backup configuration at the time of the backup.
  • Zip file: A file-based backup of the web content and the database (in the form of an SQL Server portable .bacpac file in the case of Azure SQL)

You can download the zip file from the storage account but you are also given a link for each retained backup in the Backup configuration of the web app.

Downloading the backup zip file for an Azure App Service or web app [Image Credit: Aidan Finn]
Downloading the Backup Zip File for an Azure App Service or Web App [Image Credit: Aidan Finn]

Selective Backup

It is possible to exclude files from your backups, which might be important to you if your backup size exceeds 10GB.
Tip: Azure SQL does its own backups automatically and for free. You can choose to exclude any databases to save capacity.
If you have web content that you wish to exclude from backups then you can do the following:

  1. Browse the file system of your web app to identify those files. You can use an FTP client, the web app console, or Kudu (open the web app, browse to Deployment Tools > Advanced Tools, and click Go).
  2. Identify the paths of the files and folders that you want to exclude. For example, a file called image.png in the root of the web app is stored at sitewwwrootimage.png.
  3. Create a text file called _backup.filter and put the path of each excluded file/folder into the file – one excluded item per line.
  4. Upload the _backup.filter file to the root of your web app (sitewwwroot).

The web app backup will automatically read the _backup.filter file and exclude any listed files or folders from protection.

Restoring a Backup

What good is a backup if you cannot restore it? A Restore button can be found in the Backup configuration of the web app or App Service; press this button and you can start the restore process. Here you can select the backup to restore (or provide a zip file from another App Service or web app), choose to restore to a different App Service or Web App, and decide how you will handle database connection strings and any conflicting host names.

SHARE ARTICLE