Search This Blog

Friday, January 16, 2015

Backup Azure Virtual Machine By Using Blob Snapshot

 

We have setup Virtual Machine Azure. Next question you may wonder on how to backup Azure Virtual Machine. Too bad at this moment, we cannot using System Center Data Protection Manager or Azure Backup to backup virtual machine. However can use these backup to backup application data.

Then we have search around and found out that we can use Blob Snapshot to perform backup by referring to Keith Mayer guide. You can refer to here.

There are four (4) steps that you need to in order to backup Azure Virtual Machine.

  • Select virtual machine to back up
  • Identify virtual hard disks
  • Create cloud storage container for storing backups
  • Back up virtual machines in Windows Azure to cloud storage
  • Backup VM Configuration by using Export-AzureVM

Well, we follow the guide provide by Keith Mayer and summarize it in this script:-

#to list down entire VM in Azure
Get-AzureVM

#Select 1 VM. Example: MS4UDir
$VM = Get-AzureVM -ServiceName "MS4UDIR" -Name "MS4UDIR"

#Temporary shutdown to a state when the virtual machine is not running but its configuration  is kept in a provisioned state
$VM | Stop-AzureVM -StayProvisioned

#to get os disk

$VMOsDisk = $VM | Get-AzureOSDisk
$VMOsDisk


#to get data diskname and media link
$VMDataDisks = $VM | Get-AzureDataDisk
$VMDataDisks

#determine the name of Windows Azure Storage Account by using MediaLink property
$storageAccountName= $vmOSDisk.MediaLink.Host.Split('.')[0]
$storageAccountName

#Setting the current storage account
Get-AzureSubscription | Set-AzureSubscription -CurrentStorageAccount $storageAccountName

#Creating a new Windows Azure Storage Container
$backupContainerName ="backupvhd"
New-AzureStorageContainer -Name $backupContainerName -Permission Off

#Confirming creation of storage container
Get-AzureStorageContainer

#Backup virtual machine
$vmOsBlobName = $vmOsDisk.MediaLink.Segments[-1]
$vmOsBlobName
$vmOsContainerName = $vmOsDisk.MediaLink.Segments[-2].Split('/')[0]
Start-AzureStorageBlobCopy -SrcContainer $vmOsContainerName -SrcBlob $vmOsBlobName -DestContainer $backupContainerName

#Get-AzureStorageBlobCopyState to confirm that the copy process completed
Get-AzureStorageBlobCopyState -Container $backupContainerName -Blob $vmOsBlobName -WaitForComplete

#Backup Data Disk
ForEach ($vmDataDisk in $vmDataDisks) {
$vmDataBlobName = $vmDataDisk.MediaLink.Segments[-1]
$vmDataContainerName = $vmDataDisk.MediaLink.Segments[-2].Split('/')[0]
Start-AzureStorageBlobCopy -SrcContainer $vmDataContainerName -SrcBlob $vmDataBlobName -DestContainer $backupContainerName -Force
Get-AzureStorageBlobCopyState -Container $backupContainerName -Blob $vmDataBlobName -WaitForComplete
}

#Confirm that a copy of each virtual hard disk now exist in the backup storage container location.
Get-AzureStorageBlob -Container $backupContainerName

#Start VM after backup complete
$vm | Start-AzureVM

Screenshot:

Backup1

Backup2

Backup3

Backup4

Backup5

The process is length but at last we managed to backup the virtual machine.

2 comments:

  1. Why can't we use DPM? DPM 2012 R2 in Azure is a supported scenario.

    ReplyDelete
    Replies
    1. DPM in Azure only suitable to backup data. Not entire VM on Azure. You cannot install DPM agent at Hyper-V in Azure. But you can do bare metal installation, however recovery will take longer time. By using Blob Snapshot, it will backup entire VHD into Azure Storage.

      Delete