Last active
June 24, 2019 01:34
-
-
Save myclau/f621707278974241997faa520c6e658d to your computer and use it in GitHub Desktop.
Azure move disk to different region
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Provide the subscription Id where snapshot is created | |
$SubscriptionId = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" | |
#Provide the name of your resource group where snapshot is created | |
$resourceGroupName="rgname" | |
#Provide the snapshot name | |
$SnapshotName = "snapshotname" | |
#Provide Shared Access Signature (SAS) expiry duration in seconds e.g. 3600. | |
#Know more about SAS here: https://docs.microsoft.com/en-us/azure/storage/storage-dotnet-shared-access-signature-part-1 | |
$sasExpiryDuration = "3600" | |
#Provide storage account name where you want to copy the snapshot. | |
$StorageAccountName = "vmmigration" | |
#Name of the storage container where the downloaded snapshot will be stored | |
$StorageContainerName = "vhd" | |
#Provide the key of the storage account where you want to copy snapshot. | |
$StorageAccountKey = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' | |
#Provide the name of the VHD file to which snapshot will be copied. | |
$DestinationVHDFileName = "copyedVHDfilename" | |
# if china need to add -Environment AzureChinaCloud at the back | |
Login-AzureRmAccount | |
#get disk info | |
#$Disk = Get-AzureRmDisk -ResourceGroupName $ResourceGroupName -DiskName $DiskName | |
#create snapshot config | |
#$Snapshot = New-AzureRmSnapshotConfig -SourceUri $Disk.Id -CreateOption Copy -Location $Location | |
#create snapshot | |
#New-AzureRmSnapshot -Snapshot $Snapshot -SnapshotName $SnapshotName -ResourceGroupName $ResourceGroupName | |
#create snapshot SAS Uri | |
$sas = Grant-AzureRmSnapshotAccess -ResourceGroupName $ResourceGroupName -SnapshotName $SnapshotName -DurationInSecond $sasExpiryDuration -Access Read | |
#target storage account | |
$destinationContext = New-AzureStorageContext –StorageAccountName $StorageAccountName -StorageAccountKey $StorageAccountKey | |
#copy snapshot to storageaccount | |
Start-AzureStorageBlobCopy -AbsoluteUri $sas.AccessSAS -DestContainer $StorageContainerName -DestContext $destinationContext -DestBlob $DestinationVHDFileName | |
#check copy status | |
$sto = Get-AzureRmStorageAccount -ResourceGroupName $StorageResourceGroupName -Name $StorageAccountName | |
$context = $sto.Context | |
Do { | |
$status=Get-AzureStorageBlobCopyState -Blob $DestinationVHDFileName -Container $StorageContainerName -Context $context | |
$copied=$status.BytesCopied | |
$total=$status.TotalBytes | |
$percentComplete = ($copied / $total *100) | |
Write-Progress -Activity "Copying blob" -status "Copying $copied / $total , $percentComplete %" -percentComplete $percentComplete | |
sleep 2 | |
}While ($copied -ne $total) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Install-Module -Name AzureRM -AllowClobber | |
Select-AzureRmSubscription -Tenant "xxxxxxxxxxxxxxxxxxxxxxxxxxx" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment