How to backup Citrix XenServer virtual machines

Case #

You need to take backups of the virtual machines of a Citrix XenServer hypervisor, also known as Citrix hypervisor. This article provides step-by-step guidance on how to backup Citrix XenServer virtual machines.

Solution #

Export VM snapshot to a file (works with running VM) #

Just taking snapshot of a VM is not a credible solution for restoring the VM in case an issue occurs. This is because, by design, snapshots are dependent on the VM disk itself, so if the disk gets corrupted in some way, the snapshot cannot be created to bring the VM to a functional state. If you need to have zero downtime for your VMs, you can take a VM snapshot and then export the snapshot into a file.

Inside the XenCenter console, click on the VM in question and go to the “Snapshots” tab and click “Take snapshot”.

Then right click on the taken snapshot icon and click “Export to File”.

The equivalent XenServer CLI commands are the following.

#Get the VM UUID
xe vm-list is-control-domain=false is-a-snapshot=false

#Use the above UUID in following command to create VM snapshot
xe vm-snapshot uuid=[see above output] new-name-label=snapshot01

#Use the new UUID returned by the above command (snapshot UUID) to export to a file
xe vm-export vm=[see above output] filename=vm-backup.xva

Export VM (requires the VM to be shut down) #

You can also take full backups of the Citrix XenServer VMs, in other words take a VM export. This will incur VM downtime, as it requires the VM in question to be shut down for the export to be performed.

After you have shut down the VM in question, open a console or ssh session to one of the XenServer hosts and run the following command.

#Remember to shut down the VM first. 

# In case you need to make use of a XenServer SR, run the following command to find its mount path #(usually under /var/run/sr-mount/UUID
df -h

#Now use the SR UUID as the target location for the VM export
xe vm-export vm="[VMNAME]" filename=/var/run/sr-mount/[GUID]/vm-backup.xva

On top of the above methods, you could also potentially utilize a bash script (.sh file extension) to automate the XenServer VM backup process.

Powered by BetterDocs