Citrix is a complex virtualization management platform that boasts an impressive list of features and functions. As with any virtualization management system, it’s highly recommended to have some sort of backup system in place to have a copy of your data as a safety measure.
Fortunately, Citrix XenServer backup solutions also include the capabilities to perform basic backups, meaning that there are some ways of creating a backup of both the server and the VM that require no third-party software to be created.
Citrix server backup
First of all, there’s the server-based Citrix Xen backup. It’s a Full backup method and therefore may have some limitations that may result in the creation of large files and can not work with the control domain (domain 0). Another important part of this process is that to complete this operation you’ll have to restart the system using the original installation CD.
On the backup side of things – in the “Server” tab there’s a “Back-Up Server…” button, and clicking it leads to the backup menu. The backup menu allows you to choose the target folder that will store the future backup file, and you can also change the name of the backup. Clicking “Save” should begin the procedure, and the backup progress can be tracked using the “Logs” button.
If we’re talking about restoring one of such backups, it’s even easier. All you have to do is go to the same “Server” tab and choose the “Restore from Backup” line. The following menu allows you to choose the backup that you want to restore. After the process seems complete, you’ll also have to restart the entire server using the original installation CD to complete the restoration process of your Citrix Xen backup.
Citrix VM backups
Creating backups of a running VM is a little more complicated. First of all, it’s true that it’s easy to back up a VM that’s turned off, but this may result in significant downtime, which is unacceptable for most companies. That’s why there are two main ways of creating backups for a running VM in Citrix XenServer – manual backup and backup with a script.
The manual backup consists of four main steps:
- Finding out the UUID of the VM you want to back up.
This can be done using a specific command that lists all of the currently running VMs, as well as their power state and their regular name (not UUID):
# xe vm-list is-control-domain=false is-a-snapshot=false
- Creating a snapshot.
This step consists of two different commands, one being used to create an actual snapshot of the target VM (using the UUID we’ve found out beforehand), and the other one used to convert the snapshot to a VM before exporting it in the next step:
# xe vm-snapshot uuid=*VM_UUID* new-name-label=testvmsnapshot
# xe template-param-set is-a-template=false ha-always-run=false uuid=*snapshot_UUID*
Please note that the above commands are using two different UUIDs, the first one being the VM UUID, and the second one is the snapshot UUID, thus they’re not the same.
- Exporting the snapshot’s contents to a file.
The next part is all about exporting the contents of our snapshot to a specific file with the .xva format so that we can restore it later using either the command line or the XenCenter.
# xe vm-export vm=*snapshot_UUID* filename=vm-backup.xva
- Getting rid of the snapshot.
As soon as we’re done with exporting the snapshot’s contents, we’re free to destroy the snapshot using the following command:
# xe vm-uninstall uuid=*snapshot_UUID force=true
Shell scripts are the other way of creating a running VM backup, here’s one example of such a script that mounts a remote file system exported through NFS:
#!/bin/bash
DATE=`date +%d%b%Y`
XSNAME=`echo $HOSTNAME`
UUIDFILE=/tmp/xen-uuids.txt
NFS_SERVER_IP="192.168.10.100"
MOUNTPOINT=/xenmnt
FILE_LOCATION_ON_NFS="/backup/citrix/vms"
### Create mount point
mkdir -p ${MOUNTPOINT}
### Mounting remote nfs share backup drive
[ ! -d ${MOUNTPOINT} ] && echo "No mount point found, kindly check"; exit 0
mount -F nfs ${NFS_SERVER_IP}:${FILE_LOCATION_ON_NFS} ${MOUNTPOINT}
BACKUPPATH=${MOUNTPOINT}/${XSNAME}/${DATE}
mkdir -p ${BACKUPPATH}
[ ! -d ${BACKUPPATH} ] && echo "No backup directory found"; exit 0
# Fetching list UUIDs of all VMs running on XenServer
xe vm-list is-control-domain=false is-a-snapshot=false | grep uuid | cut -d":" -f2 > ${UUIDFILE}
[ ! -f ${UUIDFILE} ] && echo "No UUID list file found"; exit 0
while read VMUUID
do
VMNAME=`xe vm-list uuid=$VMUUID | grep name-label | cut -d":" -f2 | sed 's/^ *//g'`
SNAPUUID=`xe vm-snapshot uuid=$VMUUID new-name-label="SNAPSHOT-$VMUUID-$DATE"`
xe template-param-set is-a-template=false ha-always-run=false uuid=${SNAPUUID}
xe vm-export vm=${SNAPUUID} filename="$BACKUPPATH/$VMNAME-$DATE.xva"
xe vm-uninstall uuid=${SNAPUUID} force=true
done < ${UUIDFILE}
umount ${MOUNTPOINT}
Conclusion
Citrix XenServer backup solutions offer several different backup methods that can be performed using the built-in solutions, but they are somewhat basic. In this case, it’s not uncommon for companies that use Citrix to utilize the help of some sort of third-party software with expanded capabilities.
One such software is Bacula Community, offering a free open source solution that can work with an especially large range of different systems, including Citrix, and offers an amount of features and advantages that is almost remarkable for a free solution. Bacula can create scheduled backups and allows you to customize various parameters, as well as taking advantage of a vast Bacula community that is responsive and ready to help when you need it.