I know that there are two types of virtual machine images, Generalized and Specialized.

  1. If the OS has been generalized/de-provisioned, the virtual machine must be shut down in order to capture it as a VM Image. Once the VM has been captured as a VM Image, the virtual machine will automatically be deleted.

  2. If the OS is specialized, the virtual machine can be captured while it is running or shut down. The captured virtual machine remains untouched. If an application consistent or cross-disk capture is needed, we recommend the virtual machine is shut down prior to capturing the VM Image.

Here I am trying to capture the image without shutting down the VM (Specialised). I have the below code to capture the image using PowerShell.

Save-AzureRmVMImage -ResourceGroupName $rgame -VMName $vmname  -DestinationContainerName $container -VHDNamePrefix $vhdname

but the above code throws the error as below

Save-AzureRmVMImage : Capture operation cannot be completed because the VM is not generalized.
    ErrorCode: OperationNotAllowed
    ErrorMessage: Capture operation cannot be completed because the VM is not generalized.
    StatusCode: 409

I found I can set VM to Generalized using Set-AzureRmVM

Set-AzureRmVM -ResourceGroupName 'CaptureVmImageRG' -Name 'CaptureVmImage' -Generalized 

Is there anyway so that I can set VM to Specialized and capture the image. Can someone please provide a working Powershell command to create a Specialized capture of a running VM for backup 'point in time' purposes, or any other mechanism e.g. resource explorer.

Thanks in advance.

2

There are 2 answers

5
Shui shengbao On BEST ANSWER

The commands Save-AzureRmVMimage and Set-AzureRmVM are used for captureing Generalized images. Before you run the two cmdlet, you should log on to VM and use Sysprep to prepare the hard disk.

On ARM mode, for Specialized image, I don’t think you need use cmdlet to capture the image. You could copy your VHD to another storage account. The copied VHD is a Specialized image. You could use the VHD to recreate a new VM which has your data. Based on my knowledge, you had better copy the VHD when the VM is stopped. More information please refer to the article

I think using Azure recovery services vault is a better solution. Azure supports backup your VM automatically and no need to stop your VMs. It is easy for you to recovery your VMs. More information please refer to the article.

0
badbob001 On

With classic azure, you can capture specialized VMs as use the resulting image as a quick backup. With ARM azure, the capture command expects the VM to be sysprep'ed/generalized and will actually make the original VM not boot normally anymore. We had a few scary moments when using 'capture' in ARM thinking it was like Classic.

Invoking a manual backup through Recovery Services is an option, but it takes too long! You may say that once the snapshot phase is complete and the process is in the transferring to vault phase, you can continue to use the original VM. But if the backup fails, which may not happen until many hours later, there is no snapshot or new backup to recover from.

So fastest and most reliable way to copy a VM is to just shutdown the VM and then make a copy of the vhds.