Automating Azure VM Backups Using ARM Templates

In this post I will give a quick overview of automating Azure VM backups using ARM templates. There are quick start templates for backups when you search for them but the syntax for the resource names didn’t make sense to me, hence this post to explain it a bit more. I will also touch on using Azure Resource Explorer which is a great tool for understanding the ARM API.

Azure VM Backups Background

To backup Azure VMs with Azure Backup you have to create a Recovery Services vault, create a backup policy which contains the schedule and backup retention settings and register your VMs for backups to the vault and selected policy. There are quick start templates to create vaults, policies and schedules here. Although you won’t see it from the portal there is also the notion of a container for storing backups. The type of container depends on the items that are backed up, there are containers for Azure VMs, SQL backups and Windows backups. This is the part that wasn’t clear to me in authoring ARM templates but next I’ll show you how to shed some light on them.

Azure VM Backup Resource Syntax

One way to figure out the syntax for an ARM template is to look at existing resources and export the template from the Azure Portal using the Automation script blade but that will export your vault only, not your VM backups.

Next I tried Azure Resource Explorer, drilling down to my recovery vault I didn’t see the VMs that are registered for backups or the policies but I did manage to find the deployments for them in:

{resourcegroup}\Microsoft.Resources\deployments

The deployments to create a backup policy are named CreatePolicy* and the deployments to register a VM for backups are named ConfigureProtection*. In the deployment for VM protection I managed to find the syntax for the resourceName.

Automating Azure VM Backups Using ARM Templates

The ARM template to register multiple VMs for backups is in my GitHub repo here. The template assumes the VMs are not in the same resource group as the recovery vault since the backup vault was contained in a separate management resource group in this case.

A Bit More On Azure Resource Explorer

I highly recommend taking a few minutes to take a look at the Azure Resource Explorer. It is a great way to explore the syntax for Azure ARM Rest API, there are tabs to execute some Rest API commands directly from the explorer, PowerShell samples to create the currently selected resource and documentation for the selected resource.

Francois Delport

Published by

Francois Delport

I am a cloud and devops consultant, technology fan and previously a professional C# developer with a keen interest in system design and architecture. Currently I am involved in projects using Azure, the Microsoft stack and DevOps. I am based in Melbourne, Australia. Email: [email protected]

Leave a Reply

Your email address will not be published. Required fields are marked *