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 is software-defined storage (SDS) solution created with restricted budgets and maximum output in mind. It pulls close to 100% of IOPS from existing hardware, ensures high uptime and fault tolerance starting with just two nodes. StarWind VSAN is hypervisor and hardware agnostic, allowing you to forget about hardware restrictions and crazy expensive physical shared storage.

Build your infrastructure with off-the-shelf hardware, scale however you like, increase return on investment (ROI) and enjoy Enterprise-grade virtualization features and benefits at SMB price today!

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!

Back to blog