Azure Virtual Machine Disk Snapshot Migration from one location to Another

Neeraj Singh Negi
1 min readMay 6, 2023

Here the migration goinng on for East US to Central India.

Photo by NASA on Unsplash

Snapshot Migration

Snapshot Migration to different location

Powershell script

snapshot-mg-eastus-to-india.ps1

To execute the powershell script use below command.

./snapshot-mg-eastus-to-india.ps1
$SnapshotResourceGroup = "source-resource-group-name"
$SnapshotName = "source-snapshot-name"
$StorageAccount = "dest-storage-name"
$StorageAccountcontainer = "dest-container-name"
$storageaccountResourceGroup = "dest-resource-group-name"
$snapshotshotinblobname = "dest-snapshot-name" #(it would be same as source snapshot name or different as per your preference)


Start-Sleep -Seconds 5
$snapshot = Get-AzSnapshot -ResourceGroupName $SnapshotResourceGroup -SnapshotName $SnapshotName
$StorageAccountKey = (Get-AzStorageAccountKey -Name $StorageAccount -ResourceGroupName $StorageAccountResourceGroup).value[0]
Write-Output "Granting $($SnapshotName) access"
$snapshotaccess = Grant-AzSnapshotAccess -ResourceGroupName $SnapshotResourceGroup -SnapshotName $SnapshotName -DurationInSecond 3600 -Access Read -ErrorAction stop
$DestStorageContext = New-AzStorageContext –StorageAccountName $storageaccount -StorageAccountKey $StorageAccountKey -ErrorAction stop
Write-Output "Begin snapshot: ($SnapshotName) copy to $snapshotshotinblobname.vhd"
$copy = Start-AzStorageBlobCopy -AbsoluteUri $snapshotaccess.AccessSAS -DestContainer $StorageAccountcontainer -DestContext $DestStorageContext -DestBlob "$($snapshotshotinblobname).vhd" -Force -ErrorAction stop
Write-Output "Completed snapshot: ($SnapshotName) copy to $snapshotshotinblobname.vhd"
Start-Sleep -Seconds 20
$copy | Get-AzStorageBlobCopyState
Start-Sleep -Seconds 240
$copy | Get-AzStorageBlobCopyState
Start-Sleep -Seconds 240

To see the migration progress use below command.

$copy | Get-AzStorageBlobCopyState
Start-Sleep -Seconds 240

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Neeraj Singh Negi
Neeraj Singh Negi

Written by Neeraj Singh Negi

AWS | Openstack | GCP | Ansible | Redhat 8 Linux | Docker | Jenkins | Kubernetes | Hadoop | Python | Machine Learning

No responses yet

Write a response