Azure Snapshots of managed virtual hard drives (vhds) are stored in Resource Groups (as opposed to ‘unmanaged’ Snapshots being stored in storage accounts). While it is possible to move the managed snapshots to another subscription using PowerShell, there are advantages to having a copy of crucial core snapshots readily available and protected as a Page Blobs in a Storage Account.
With PowerShell, copies of the Snapshots can be exported to an Azure Storage Account to be able to:
- Maintain a separated set of crucial snapshot copies that cannot be deleted by accident, helpful as another Disaster Recovery point
- Quickly & easily copy Snapshots to a different Azure account or subscription using Microsoft Azure Storage Explorer and then create new managed disks and VMs in the different Account or subscription
- At the time of this writing, VMs with managed disks cannot be moved from one Azure region to another. The workaround is to export a snapshot of the VMs managed disks to a storage account in a different region, and then re-create the VM with the managed disk(s) in a Resource Group in the different region. Read more here.
1. #Login to Azure Portal (read here for a slick way to select the correct subscription context)
2. #Declare Variables:
$resourceGroupName = '<Your Snapshot Resource Group>'
$snapshotName = '<Your Snapshot Name>'
$resourceGroupNameStorageAccount = '<Name of the Resource Group of Destination Storage Account>'
$storageAccountName = '<Name of Destination Storage Account>'
$storageContainerName = '<Name of Storage Container in Storage Account for snapshot download>'
$destinationVHDFileName = '<Name of the new VHD file of the SnapShot>'
3. #Get the Storage Account Key of the Destination Storage Account
$storageAccountKey = Get-AzureRmStorageAccountKey
#Generate the SAS for the snapshot
$sas = Grant-AzureRmSnapshotAccess -ResourceGroupName $resourceGroupName
-SnapshotName $snapshotName -DurationInSecond 3600 -Access Read
#Create the context of the destination storage account for the snapshot
$destinationContext = New-AzureStorageContext –storageAccountName
$storageAccountName -StorageAccountKey ($storageAccountKey).Value
#Copy the snapshot to the destination Storage Account
Start-AzureStorageBlobCopy -AbsoluteUri $sas.AccessSAS
-DestContainer $storageContainerName -DestContext $destinationContext
It took less than 20 seconds to get the snapshot (‘W10Pro-OS-Snapshot’ in example below) to a Storage Account in PowerShell (same subscription). In reality, PowerShell only triggers the copy – the blob’s properties will have “COPY STATUS: PENDING” meaning the copy is ongoing in the backend.
In Microsoft Azure Storage Explorer, the Snapshot file (‘W10Pro-OS-Snapshot’ in example below) copied to the Storage Account is showing as a 127.0 GB Page Blob: