Automating Disk Snapshots

Introduction

There are two ways to backup your Azure Virtual Machines: First method is using the Azure Backup service in order to backup Virtual Machine periodically based on a backup policy. The Azure Backup service backs up data from on-premises machines, and Azure VMs. Data can be backed up and recovered at a granular level. Second method is creating VM disk snapshots in order to backup a disk manually. It is great when you try to backup a VM for which Azure Backup can not be used.

In this article, I will explain the second option in order to automate the process of creating disk snapshots using PowerShell.

Creating Azure Runbook

In this article, I will create daily snapshots of the disks which have associated tagname ‘Snapshot’ with tagvalue ‘True’. First, we have to create the tag on the Virtual Machines that must be snapshotted. Open the Azure Portal, navigate to the Virtual Machine blade and ‘Tags’:

Creating Azure Runbook

Now, we can create the Runbook from the Azure Automation blade. If you don’t already have an existing automation account, then create a new one.

Click ‘+ Create a runbook

Runbook

And enter the following information:

  • Name: It is a friendly name for the Runbook
  • Runbook Type: Select PowerShell in this case, but you can select another type if needed
  • Description: it is optional, but you can describe the goal of this runbook

Runbook name

The runbook is created, but before going deeper, we must update the modules. Go to ‘Modules gallery’ and search for ‘AzureRM.Resource’ which is a module we need in the runbook.

Une image contenant capture d’écran Description générée automatiquement

In order to import the module, click ‘Import

AzureRM.Resources

Before validating the wizard, select the checkbox in order to update all the modules.

Agree to update all the modules

Go back to the ‘Modules’ blade and confirm that the module is available

Modules

Now, edit the runbook and copy/paste the following PowerShell code.

Publish the Runbook when everything is ok, and then go back to the Azure Automation Account and select Schedules. Click on ‘Link to schedule’.

wp-image-13081

Link to schedule

You can confirm the schedule is created

Schedule is created

VSAN from StarWind eliminates any need for physical shared storage just by mirroring internal flash and storage resources between hypervisor servers. Furthermore, the solution can be run on the off-the-shelf hardware. Such design allows VSAN from StarWind to not only achieve high performance and efficient hardware utilization but also reduce operational and capital expenses.

Learn more about ➡ VSAN from StarWind

You just need to wait until the runbook start, then a snapshot will be created

Create disk snapshot

Conclusion

Thanks to Azure Automation, you can very easily and quickly deploy a Runbook to backup a Virtual Machine. You can also automate tasks that you performed manually.

Thanks for reading!

Views All Time
3
Views Today
16
Appreciate how useful this article was to you?
1 vote, average: 5.00 out of 51 vote, average: 5.00 out of 51 vote, average: 5.00 out of 51 vote, average: 5.00 out of 51 vote, average: 5.00 out of 5
5 out of 5, based on 1 review
Loading...
Back to blog
The following two tabs change content below.
Nicolas Prigent
Nicolas Prigent
Nicolas Prigent works as a System Engineer, based in Switzerland with a primary focus on Microsoft technologies. Nicolas is Microsoft MVP in Cloud And Datacenter Management with 8 years experience in administering Windows Servers, Hyper-V and System Center products. He also received the "PowerShell Heroes 2016" Award.