Copying your VM Disk to Storage account

To copy the VM disk to your storage account follow the below steps

Step 1: Create a New Storage account and a container inside in it

Step 2: Then open the Azure CLI

Step 3: Then execute the below script in AzureCLI

#Provide all the details as shown below
$subscriptionId = "3902ccd9-9777-4de2-a0a6-eefa61b34ca5"
$resourceGroupName ="yourResourceGroupName"
$managedDiskName = "yourManagedDiskName" 
$sasExpiryDuration = "3600"
$storageAccountName = "yourstorageaccountName"
$storageContainerName = "yourstoragecontainername"
$storageAccountKey = "yourStorageAccountKey"
$destinationVHDFileName = "yourvhdfilename"

#Logs in to the Azure Account & Select AzureRM subscription
Login-AzureRmAccount
Select-AzureRmSubscription -SubscriptionId $SubscriptionId

#Generate the SAS for the managed disk
$sas = Grant-AzureRmDiskAccess -ResourceGroupName $resourceGroupName -DiskName $managedDiskName -Access Read -DurationInSecond $sasExpiryDuration
$destinationContext = New-AzureStorageContext –StorageAccountName $storageAccountName -StorageAccountKey $storageAccountKey

#Copy the snapshot to the storage account and wait for it to complete
Start-AzureStorageBlobCopy -AbsoluteUri $sas.AccessSAS -DestContainer $storageContainerName -DestContext $destinationContext -DestBlob $destinationVHDFileName
while(($state = Get-AzureStorageBlobCopyState -Context $destinationContext -Blob $destinationVHDFileName -Container $storageContainerName).Status -ne "Success") { $state; Start-Sleep -Seconds 5 }
$state 

This will copy the VM disk to VHD file (Virtual Hard Disk )

And the below command will upload the status as shown


You may also like...

6 Responses

  1. November 14, 2020

    … [Trackback]

    […] Info on that Topic: azuredevopsguide.com/copying-your-vm-disk-to-storage-account/ […]

  2. November 19, 2020

    … [Trackback]

    […] Read More on that Topic: azuredevopsguide.com/copying-your-vm-disk-to-storage-account/ […]

  3. November 21, 2020

    … [Trackback]

    […] There you can find 56760 additional Info on that Topic: azuredevopsguide.com/copying-your-vm-disk-to-storage-account/ […]

  4. November 24, 2020

    … [Trackback]

    […] There you can find 87693 more Information on that Topic: azuredevopsguide.com/copying-your-vm-disk-to-storage-account/ […]

  5. November 30, 2020

    … [Trackback]

    […] Info on that Topic: azuredevopsguide.com/copying-your-vm-disk-to-storage-account/ […]

  6. December 1, 2020

    … [Trackback]

    […] Here you will find 14369 more Information on that Topic: azuredevopsguide.com/copying-your-vm-disk-to-storage-account/ […]