Make a Backup of a Live Citrix Xenserver 6.2 VM with No Downtime

Edited by Inukshuk, Eng, Genady, Maria Quinney and 5 others

XenServer Logo.jpg

One of the great features of running a virtual machine (VM) environment is to have the ability to clone an existing VM for either testing or expansion purposes, or for disaster recovery to quickly replace a failed server. Unfortunately this seems to be one place where Citrix has failed badly in both the built-in functionality of what XenCenter can do, and also in the documentation of what is available from the CLI (command-line interface). Fortunately though, it can be done in only a few steps with the right setup.

Background on XenServer Copy, Snapshots, Templates and Storage

XC HomeTab Anno.png

The seemingly obvious feature of 'Copy' built-in to XenCenter has the unfortunate requirement that the VM be shutdown completely during the copy. Not something you want to do if the VM is hosting active websites. What needs to be done instead is to create a snapshot of the VM, then create a template based on that snapshot. At this point, the original snapshot can be deleted. Any new VM can now be created based on this new template.

The next problem to overcome is where to store the templates. It's important to understand how XenServer uses the disk space. You need as much free space on the disk as the VM to create a template. Maybe not a big deal if you've got big disks and small VMs, but it can really be a problem if you've paid extra for some high-speed SSD's (if you've got a >100G VM on a 200G SSD, it is impossible to create a local template/backup). You do need some free space locally to create the snapshot, but I can't find any documentation anywhere, nor can I get a response from Citrix, on how it works. I've created snapshots with as little as 10% of the size of the VM free on the host, but I have no idea what the minimum is.

Templates can be exported to an .xva file to an external NFS if desired, but the problem with this solution is that when you want to use that file, you have to import it to a XenServer host within your pool - just to create the template - and then create a new VM based on that template. So you still need 2 separate chunks of free space within your pool each the size of the VM for this method to work.

A much easier solution is to have your backup server in your pool with the rest of your host machines, create the templates there, and when needed, create any new VMs based directly of those templates. It happens in one step, at whatever your network speed is to copy the size of the VM from your backup to your new host.


  1. 1
    Install your backup server with the same version of XenServer and add it to your Pool.
    Was this step helpful? Yes | No| I need help
  2. 2
    Get the uuid of the storage repository (SR) on the backup server
    xe sr-list host="name of backup host"
    It will most likely be labelled "Local Storage" or something similar - note the uuid (sruuid in future steps).
    Was this step helpful? Yes | No| I need help
  3. 3
    Create a snapshot of the vm to be backed up
    xe vm-snapshot vm="vmname" new-name-label="vmname-snap-date"
    Note the uuid output from this command (snapuuid in future steps).
    Was this step helpful? Yes | No| I need help
  4. 4
    Create the template on the destination SR
    This is the step that cannot be done through XenCenter, and must use the CLI - the key point is the sr-uuid.
    xe snapshot-copy new-name-label="vmname-template-date" new-name-description="Template of vmname created on date" uuid=snapuuid sr-uuid=sruuid
    Was this step helpful? Yes | No| I need help
  5. 5
    Remove the snapshot
    xe snapshot-uninstall force=true snapshot-uuid=snapuuid
    Was this step helpful? Yes | No| I need help

Shell Script For Cron Job Backup


#the uuid of the destination storage repository

curdate=$(date +%Y%m%d)

for vmname in vm1 vm2 vm3

echo "$(date +"%Y-%m-%d %k:%M:%S") -- ${vmname} -- Creating snapshot." >> ${logfile}

snapuuid=`xe vm-snapshot vm=${vmname} new-name-label=${vmname}-snap-${curdate}`

echo "$(date +"%Y-%m-%d %k:%M:%S") -- ${vmname} -- Snapshot created.  UUID=${snapuuid}.  Copying to SR." >> ${logfile}

xe snapshot-copy new-name-label=${vmname}-template-${curdate} new-name-description="Template of ${vmname} created ${curdate}" uuid=${snapuuid} sr-uuid=${sruuid}

echo "$(date +"%Y-%m-%d %k:%M:%S") -- ${vmname} -- Template created on SR.  Deleting snapshot." >> ${logfile}

xe snapshot-uninstall force=true snapshot-uuid=${snapuuid}

echo "$(date +"%Y-%m-%d %k:%M:%S") -- ${vmname} -- Backup complete." >> ${logfile}


Questions and Answers

Can't copy snapshot to remove sr?

Hi, when I ran xe snapshot-copy I got The uuid you supplied was invalid. uuid - is a second server local storage sruuid. Can you, please explain?

The uuid in the snapshot-copy command should be the one you got as output from the xe vm-snapshot command. The sr-uuid in the snapshot-copy command is the ID of the storage repository on the destination where you are going to save your backup (you find it with the xe sr-list command). Make sure you didn't put the wrong uuid in the wrong place. It can be a bit confusing, since I believe all items (vm, disk, controller, snapshot, etc) in XenServer are identified by uuid's and there's no way to tell them apart later other than to note the output from the commands used to find them.

Also remember that both hosts (the one with the live VM + the one storing the backups) must be in the same pool or else they cannot communicate with each other.

I am searching for a script to restart vm's at night?

I am searching for a script to restart vm's at night. That is no problem with a stand alone server. But I have two on a pool. So how can I tell the script to check which VM is running on which server. Thanks

VisiHow QnA. This section is not written yet. Want to join in? Click EDIT to write this answer.

I want to export VMs without downtime?

Hi, I want to export VMs without downtime and the worse thing is, there is no space left to take snapshot now I want to copy these VMs without downtime to another host ASAP, your help will be extremely appreciated

VisiHow QnA. This section is not written yet. Want to join in? Click EDIT to write this answer.

How can I delete old templates with this script?

So, your script is very useful to me. I put 2 scripts of these in my crontab root, but I would like to do this script to delete old templates. Is it possible? If yes, how? Thanks.

VisiHow QnA. This section is not written yet. Want to join in? Click EDIT to write this answer.

If you have problems with any of the steps in this article, please ask a question for more help, or post in the comments section below.


Article Info

Categories : System Administration

Recent edits by: redisztribucio, Dougie, GemmricherIT

Share this Article:

Thanks to all authors for creating a page that has been read 18,258 times.


Thank Our Volunteer Authors.

Would you like to give back to the community by fixing a spelling mistake? Yes | No