I know that there are two types of virtual machine images, Generalized and Specialized.
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.
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.
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.