Lead Image © meepiangraphic, 123RF.com
Snapshot management for Azure VMs
It's a Snap
Snapshots are a key tool in virtual machine (VM) management. They offer a quick and easy way to back up the status of a VM at a specific point in time – without having to shut down machines or interrupt production operations. This option is particularly useful in cases of misconfiguration, data loss, or system failure and is useful in development and test environments that require fast clones.
Snapshot Benefits
One key advantage of snapshots is a flexible basis for backup and recovery strategies. Organizations can use them to create a backup quickly without affecting the original state of the VM. Additionally, snapshots enable very efficient management of large infrastructures with the use of sophisticated storage mechanisms that only save the changes since the last snapshot, saving storage space and money.
In Azure, snapshots also have the option of creating a new disk from an existing snapshot of a virtual disk. In turn, the disk can form the basis for a new virtual machine. By creating a new virtual disk from a snapshot, you can create an exact copy of the original state of the VM without disrupting the operation of the active VM.
Snapshots are also an efficient choice if you need to deploy new virtual machines. Instead of reconfiguring a new VM from scratch, you simply take a snapshot and create an identical copy of the original environment, saving time and resources. This method also helps you maintain a consistent and standardized environment, because the newly created VMs have the same configuration as the original machine.
Snapshots offer another advantage in terms of integration with Azure Automation and Azure Backup, which support automated management and the regular creation of snapshots. You can also configure access controls for snapshots to ensure that only authorized users have access.
Deploying templates for the Azure Resource Manager (ARM) means that snapshots can also be used in the scope of infrastructure-as-code strategies, which improves repeatability and consistency in the provisioning of VM environments. By way of an example, snapshots can be used with Terraform to automate the provisioning of Azure VMs.
Incremental by Default
Snapshots in Azure are incremental: Only the data that has changed since the last backup is saved. If required, you can also create a complete backup of a virtual disk on the basis of a snapshot, although this option will require more storage space.
Snapshots make it easier to clone virtual machines on the web portal, but you can also use PowerShell in the scope of automation. Azure snapshots are read-only copies of the virtual hard disk state of a VM that are stored as disk snapshot objects on Azure storage. All operations take place directly in the cloud. Snapshots can be used in a variety of ways – for example, to back up just the VM configuration or to create new managed volumes that can be docked onto existing or new virtual machines.
Restoring from snapshots is efficient, because the VM can usually be put back into operation within a few minutes because of its incremental nature. You do not need to create a special snapshot type, but you can create arbitrary new virtual disks from all snapshots and dock them onto VMs. This method also works for operating system volumes.
Snapshots in PowerShell
To create snapshots of Azure VMs with PowerShell on Windows 10/11, you need the Azure PowerShell module. To install the module locally on Windows, use
Install-Module -Name Az -AllowClobber -Scope CurrentUser
After installing the module, you can connect to Azure with Connect-AzAccount. After logging in, you can then create snapshots directly. To do this, you need the relevant resource information, such as the resource name, the resource group, and the disk names of the VMs. You can also save the data as a variable up front and then create the snapshot on the basis of the variable:
$resourceGroupName = "<resource group name>" vmName = "<name of the VM>" $disk = Get-AzDisk -ResourceGroupName $resourceGroupName -DiskName "$vmName_OsDisk_1"
The configuration object defines the specific properties of the snapshot, plus the source: that is, the disk to be backed up, the type of storage (standard or premium), the encryption settings, and the access authorizations. You can create a snapshot configuration object with
$snapshotConfig = New-AzSnapshotConfig -SourceUri $disk.Id-Location $disk.Location -CreateOption Copy
Then you can start the snapshot:
New-AzSnapshot -ResourceGroupName $resourceGroupName -SnapshotName "<snapshot name>" -Snapshot $snapshotConfig
The newly created snapshots are then available on the Azure portal but can also be used and queried with PowerShell. Windows PowerShell is particularly interesting for creating snapshots because you can work with scripts to execute multiple functions or for automation along with Azure Automation and Terraform.
Buy this article as PDF
(incl. VAT)
Buy ADMIN Magazine
Subscribe to our ADMIN Newsletters
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Most Popular
Support Our Work
ADMIN content is made possible with support from readers like you. Please consider contributing when you've found an article to be beneficial.
