How to Archive Azure VM to Storage Account Blob?

Create Disk Snapshot and Generate Snapshot Export URL

Step 1: Open Azure Portal >> Sign In and authenticate with your Azure account.

Step 2: Access Azure Virtual machines and select your target Azure VM that you wish to archive.

Step 3: After selecting the Azure VM, select Disk from the VM dashboard (Menu Section)

Step 4: Now, select the virtual machine OS disk or data disk which ever you want to archive of your choice.

Step 5: Create a snapshot of your select disk type either operating system (OS) disk or data disk.

What is Snapshot?

Quick Answer: A snapshot is a full, read-only copy of a virtual hard disk (VHD) which help in restore or rebuild a Virtual machine.

Generate Snapshot export URL

Follow the steps to generate export URL from Azure VM disk snapshot:

Access the Azure Portal >> access Snapshots >> select your target Snapshot >> now from the left pane Settings >> select Snapshot export >> In label box enter URL expiry time in seconds (Default: 3600 Seconds) >> click on Generate URL >> copy Export URL ( you use this URL for archiving to storage account.

Archive Azure VM VHD File to Azure Storage Blob 

Pre-requisite: User or Service Principal should have additional RBAC role that is Storage Account Blob Owner or Storage Account Blob Contributor role access to perform this archiving.

Follow the step to archive azure virtual machine .vhd file to storage account container:

Step 1: Sign in to Azure Portal and access Azure Cloud Shell >> switch to Bash Terminal

Step 2: Login to your Azure Tenant account using the following command.

azcopy login --tenant-id="<add your tenant id>"

Step 3: To sign in use the web browser to open the page - https://microsoft.com/devicelogin and Enter the Code xxxxxx to authenticate.

Step 4: Modify and run the following command to archive the disk file to storage container blob with blob type PageBlob.

azcopy copy \
"<add snapshot export URL><_add_snapshot_export_url_>" \
"https://<storageaccount_name><_add_azure_storageaccount_name_>.blob.core.windows.net/<container_name><_add_container_name_>/<add your archive filename><_add_snapshot_name_>.vhd" \
--blob-type PageBlob

Modify and run the following command to archive the disk file to storage container blob with blob type BlockBlob.

azcopy copy \
"<add snapshot export URL><_add_snapshot_export_url_>" \
"https://<storageaccount_name><_add_azure_storageaccount_name_>.blob.core.windows.net/<container_name><_add_container_name_>/<add your archive filename><_add_snapshot_name_>.vhd" \
--blob-type BlockBlob

Step 5: Verify the deployment and navigate to your target Azure Storage account from Azure Portal and change the blob access tier of the file to archive state.

Restore an Archived File from Azure Storage Blob

While a blob is in the Archive access tier, it's considered to be offline and can't be read or modified. In order to read or modify data in an archived blob, you must first re-hydrate the blob to an online tier, either the Hot or Cool tier.

There are two options for re-hydrating a blob that is stored in the Archive tier:

  • Copy an archived blob to an online tier
  • Change a blob's access tier to an online tier

Method 1: Copy an archived blob to an online tier

Copy an archived blob to an online tier using Azure CLI:

az storage blob copy start \
--source-container <source-container> \
--source-blob <source-blob> \
--destination-container <dest-container> \
--destination-blob <dest-blob> \
--account-name <storage-account> \
--tier hot \
--rehydrate-priority standard \
--auth-mode login

Copy an archived blob to an online tier using Azure PowerShell:

# Initialize these variables with your values.
$rgName = "<resource-group>"
$accountName = "<storage-account>"
$srcContainerName = "<source-container>"
$destContainerName = "<dest-container>"
$srcBlobName = "<source-blob>"
$destBlobName = "<dest-blob>"

# Get the storage account context
$ctx = (Get-AzStorageAccount `
        -ResourceGroupName $rgName `
        -Name $accountName).Context

# Copy the source blob to a new destination blob in Hot tier with Standard priority.
Start-AzStorageBlobCopy -SrcContainer $srcContainerName `
    -SrcBlob $srcBlobName `
    -DestContainer $destContainerName `
    -DestBlob $destBlobName `
    -StandardBlobTier Hot `
    -RehydratePriority Standard `
    -Context $ctx

Method 2: Change a blob's access tier to an online tier

Change a blob's access tier to an online tier using Azure CLI:

az storage blob set-tier \
    --account-name <storage-account> \
    --container-name <container> \
    --name <archived-blob> \
    --tier Hot \
    --rehydrate-priority Standard \
    --auth-mode login

Change a blob's access tier to an online tier using Azure PowerShell:

# Initialize these variables with your values.
$rgName = "<resource-group>"
$accountName = "<storage-account>"
$containerName = "<container>"
$blobName = "<archived-blob>"

# Get the storage account context
$ctx = (Get-AzStorageAccount `
        -ResourceGroupName $rgName `
        -Name $accountName).Context

# Change the blob's access tier to Hot with Standard priority.
$blob = Get-AzStorageBlob -Container $containerName -Blob $blobName -Context $ctx
$blob.BlobClient.SetAccessTier("Hot", $null, "Standard")

Restore Archive File from Azure Portal:

Select the blob that you want to restore >> In the top menu click on Change Tier >> Change the Access tier as Hot or Cool >> Select the rehydrate property as Standard or High(will cost more) >> Once the rehydration process is complete you can download the file.

Note: Rehydrating a blob from Archive to Hot or Cool may take several hours to complete.