The Blog

Citrix XenServer backup without downtime. Posted on

I am working with Citrix XenServer from many years and managing all XenServers using XenCenter installed on a standalone windows machine. We regularly takes backup of VMs manually till today, I was taking backup after shutting down the VMs. Most of VM owner getting disappointed due to server down for a long time. While searching with the google I found a better way to back up VMs without shutdown them. It means we can take running vm backups and not downtime occurred.

In this article we will help you step by step backup process of running vm. Also here is a shell script which can take all vms backup or specified vm backup, which we can schedule through cron.

1. Steps to Manually Backup Running VM

Following steps also can be performed through XenCenter, But Linux lovers loves command line. So find below commands to do it.

1.1. Find VMs UUID

Use the following command to get list of UUIDs of all vms along with other details. this UUID will be used in next step

# xe vm-list is-control-domain=false is-a-snapshot=false
uuid ( RO)           : 8ac95696-94f3-83c1-bc89-8bb2603f832b
     name-label ( RW): test-vm
    power-state ( RO): running

As per above output test-vm uuid is “8ac95696-94f3-83c1-bc89-8bb2603f832b“. It can be different in your case.

1.2. Create VMs Snapshot

Now use the following command to create snapshot of vm using uuid found in above step. Make sure you are using correct uuid.

# xe vm-snapshot uuid=8ac95696-94f3-83c1-bc89-8bb2603f832b new-name-label=testvmsnapshot

Above command will retrun a UUID of snapshot, Use that UUID to convert snapshot to a vm, so we can export it to file using below command.

# xe template-param-set is-a-template=false ha-always-run=false uuid=b15c0531-88a5-98a4-e484-01bc89131561

1.3. Export Snapshot to File

Now we can export created snapshot to .xva file, Which can be easily restored from command line or XenCenter.

# xe vm-export vm=b15c0531-88a5-98a4-e484-01bc89131561 filename=vm-backup.xva

1.4. Destroy Snapshot

Finally as we have already taken backup to xva file, so we can destroy created snapshot from xenserver.

# xe vm-uninstall uuid=b15c0531-88a5-98a4-e484-01bc89131561 force=true

2. Bash Script for Backup Running VMs

To backup all vms running on XenServer, we can use following shell script also. This script mounted remote file system exported through NFS. This Scripts works for me perfectly, but it may not for you. So use this script on your own risk.

# Written By: Mr Rahul Kumar
# Created date: Jun 14, 2014
# Last Updated: Jan 22, 2016
# Version: 1.2
# Visit:

DATE=`date +%d%b%Y`

### 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}:/backup/citrix/vms ${MOUNTPOINT}

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
    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}
This entry was posted in Linux, Virtualization, XenServer. Bookmark the permalink.

Please Post Your Comments & Reviews

Your email address will not be published. Required fields are marked *

Change the CAPTCHA codeSpeak the CAPTCHA code