Azure Virtual Machine Disk Snapshot Migration from one location to Another
Here the migration goinng on for East US to Central India.
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