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

Edited by Inukshuk, Anonymous, Eng, Genady 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.

Was this helpful? Yes | No | I need help

Ad

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.

Was this helpful? Yes | No | I need help

The next problem to overcome is where to store the templates. It is 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 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.

Was this helpful? Yes | No | I need help

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.

Was this helpful? Yes | No | I need help

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 vm's 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.

Was this helpful? Yes | No | I need help

Steps

  1. 1
    Install your backup server with the same version of XenServer and add it to your Pool.
    Advertisement
    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).
    Advertisement
    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

    Advertisement

Shell Script For Cron Job Backup

#!/bin/sh

logfile="/path/vmbackup.log"
#the uuid of the destination storage repository
sruuid="12345678-90ab-cdef-1234-567890abcdef"

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

for vmname in vm1 vm2 vm3
do

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}

done

Was this helpful? Yes | No | I need help

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.

Was this helpful? Yes | No | I need help

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 at 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

Was this helpful? Yes | No | I need help

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

I want to export VM's without downtime?

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

Was this helpful? Yes | No | I need help

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.

Comments

VisiHow welcomes all comments. If you do not want to be anonymous, register or log in. It is free.




Inukshuk
Featured Author
6 Articles Started
2,093 Article Edits
60,090 Points
Inukshuk is a featured author with VisiHow. Inukshuk has achieved the level of "Major" with 60,090 points. Inukshuk has started 6 articles (including this one) and has also made 2,093 article edits. 28,100 people have read Inukshuk's article contributions.
Inukshuk's Message Board
Inukshuk: Hi, my name is Inukshuk.
Inukshuk: Can I help you with your problem about "Make a Backup of a Live Citrix Xenserver 6.2 VM with No Downtime"?
 

Article Info

Categories : System Administration

Recent edits by: Dougie, GemmricherIT, Visihow Admin

Share this Article:

Thanks to all authors for creating a page that has been read 17,469 times.

Do you have a question not answered in this article?
Click here to ask one of the writers of this article
x

Thank Our Volunteer Authors.

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