Create an Azure Disk Snapshot — PowerShell

  • For custom backup/restore of a VMs vhds
  • For troubleshooting disk problems.
  • To create a copy of production servers for use in development, or the opposite, copy a dev environment into production mode.
  • To quickly duplicate a fresh VM instance. For example, we use specific single-tier and double-tier web server/sql server environments that need to be reproduced for various testing scenarios. A new ‘exact copy’ environment, with all accounts and applications in place, can be ready for access within 5 minutes if necessary, using stored Azure Snapshots of the OS and data disks. These are considered ‘specialized’ disks…
  • To create a ‘repository’ of prepared OS and data disks for use in creating multiple VM copies.
  • To create a dr backup repository of snapshots in a different region or subscription (or both), in case of accidental deletion of key OS or data disks.
  • Backing up a VM before making a major change — although it is not possible to revert the VM to the previous state, the VM can be deleted and using the saved snapshots > create new managed OS and data disks > create a new VM using the previous VMs Nic, etc.
  • While a snapshot can be taken of an active disk, it is recommended to shut the VM down before taking a snapshot
  • Managed Disk snapshots are used to create a point in time copy of an existing disk that can then be used to create a new VM
  • You need to create a managed disk from a snapshot before it can be used with a VM
  • These directions are for taking a snapshot of a managed OS disk in these examples — ARMs default vhds.
  • Add your own values for the parameters in the POSH below.
Login-AzureRmAccount
Get-AzureRMSubscription
Select-AzureRmSubscription -SubscriptionName '<Your Subscription Name>'
$resourceGroupName = "<Your Resource Group Name>"
$vmName="<Name of VM>"
$Location = "<Your Location>"
$snapshotName = "<Snapshot Name>"
$vm = get-azureRmVm -ResourceGroupName $resourceGroupName -Name $vmName
$vmOSDisk=(Get-AzureRmVM -ResourceGroupName $resourceGroupName -Name $vmName).StorageProfile.OsDisk.Name
$Disk = Get-AzureRmDisk -ResourceGroupName $resourceGroupName -DiskName $vmOSDisk
$SnapshotConfig = New-AzureRmSnapshotConfig -SourceUri $Disk.Id -CreateOption Copy -Location $Location
$Snapshot=New-AzureRmSnapshot -Snapshot $snapshotConfig -SnapshotName `
$snapshotName -ResourceGroupName $resourceGroupName

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store