Educational ICT Virtualisation Specialist

Twitter LinkedIn E-mail
Precedence Technologies Ltd
Technology House, 36a Union Lane
Cambridge, CB4 1QB, United Kingdom
T: +44 (0)8456 446 800 / +44 (0)1223 359900
F: +44 (0)8456 446 899 / +44 (0)1223 359459

Jump To: Support > KB > Backup > XenServer

Backing up XenServer VMs with NetManager Backup Server

Backing up as templates or live VMs


  1. Locate the XenServer scripts provided by Precedence as part of a supported XenServer installation. These will tend to be in the XenServer directory in root's home area on the XenServer pool master (for these examples, we assume the pool master is called xenserver01). Ensure that you have the latest version of the backupvm script.
  2. An iSCSI storage repository will have been created using the NetManager backup server as the backend storage. Determine the name of this storage repository (usually Backup).
  3. Decide whether you want to create the backup as a new runnable virtual machine (i.e. can be immediately started up and run from the backup storage) or as a template (i.e. will need to have a new VM created from it).
  4. Decide which VMs to backup. In many cases, it makes more sense to backup the data within the VM using the NetManager backup agent. This is especially true in the case of fileservers. Examples of machines it is a good idea to backup are: Citrix datastore, one of your XenApp servers (if they are not provisioned), printer server, provisioning server database, domain controller.

Doing a manual backup

N.B. These instructions have been updated for version 1.34 of the backupvm script. Please ensure that you have the latest version before starting.

  • Go to command prompt on the pool master
  • Check the current version of the backupvm script with the -h option:
[root@xenserver01 ~]# sh XenServer/backupvm -h
Reading ~/backupvm.conf
$Revision: 1.34 $
Syntax: backupvm [-aceiltmrp] [-f <file>] [-g #] [-s <sr>]
                [-i <email>] [-x <email>] [-o <server> ] <vm> [<vm> ...]
        -t = save as template (*)
        -m = save as runnable virtual machine (*)
        -r = backup all running machines
        -s = storage repository to backup to (*)
        -l = list VMs to be backed up and exit
        -a = Backup all VMs except those excluded
        -p = add prefix with date and time to output lines
        -g = number of generations to keep (i.e. delete rest) (*)
        -c = clean up older copies (see -g), do not do new backup
        -e = do not copy VM before exporting, export directly. Only valid
             for copy or export actions and only on non-running machines
        -f = log to file
        -i = email log to given address (needs mailhub set or -o option)
        -x = email address to send from (defaults to dest)
        -o = name/IP of SMTP server (*)

If backupvm.conf is present, this will be used if no options given.
Options with (*) above override the settings in backupvm.conf.
VMs listed on command line will override those set in backupvm.conf
  • If Revision is not listed or is less than 1.34, please get the latest version from Precedence before continuing
  • Run the backupvm script specifying the backup type (vm or template), storage repository and then a list of VMs. Name with spaces in need to be quoted and all names are case-sensitive. For the first argument, use -m for a live VM and -t for a template. Specify the storage repository with the -s flag. This example will backup dc01 and Print Server to the backup storage called Backup:
[root@xenserver01 ~]# sh XenServer/backupvm -m -s "Backup" dc01 "Print Server"
Taking snapshot of dc01
Copying dc01 to backup storage
Deleting snapshot
Set template as runnable VM
Taking snapshot of Print Server
Copying Print Server to backup storage
Deleting snapshot
Set template as runnable VM

The backups will be created as new virtual machines (or new templates) and will be visible within XenCenter in the same way as any other VMs or templates. The name of the backup will be the name of the original VM with the date of the backup on the end (e.g. DC01 20101213 for a backup of DC01 taken on 13th December 2010). Therefore, old backups can be deleted from within XenCenter using the usual methods.

If the backup has been created as a live VM, you must be very careful not to start up the backup if the original is already running.

Configuring a standard backup regime to a specified storage repository (as a machine or template)

First ensure you have the latest version of the backupvm script as detailed above.

A text file called backupvm.conf in root's home area on the XenServer can contain standard settings. For example:

  • action = state to leave backup in, for use with a single pool use either machine or template. To export .xva files, use export and set exportdir. To copy from another pool, use copy and set server, user, password and exportdir
  • sr = name of the Storage Repository to backup to. If not specified, it will backup to the same Storage Repository the VM is already on. Not required if backing up another pool.
  • generations = the number of copies of a VM to keep (to keep all versions, set to 0 or don't set)
  • vms = comma-separated, case-sensitive list of VM names
  • backup = class of machines to backup (instead of hardwired vms line). This should contain either running to backup all running VMs or tag: followed by a tag name (e.g. tag:Backup to backup on the basis of VM tags).
  • exclude = comma-separated, case-sensitive list of VM names to exclude (e.g. if you choosen to backup all running VMs, but want to skip one)
  • server = IP address of pool master (only used when backing up from another pool)
  • user = root username (only used when backing up from another pool)
  • password = password for user specified by user (only used when backing up from another pool)
  • exportdir = path to export VMs to as .xva file. If action is set to copy, this is used only as temporary storage (files will be deleted after copy was successful).
  • mailhub = name/IP of SMTP server to send mail via
  • emailto = email address to send emails to
  • emailfrom = email address to send emails from
  • logfile = location to log all output to

If using tags to select which VMs are to be backed up (e.g. backup="tag:Backup"), all VMs that are tagged with the matching name exactly (case-sensitive) will be selected (for example, Backup will be backed up, backup will not). You can also put a list of days of the week (1=Monday) as numbers after a colon following the tag on the VM. For example, a VM with tag Backup:135 will be backed up only on Monday, Wednesday and Friday (assuming that the backupvm script is run nightly). In this way, some VMs can be backed up more frequently than others.

Once created, you can just run the backupvm script by itself to backup all the configured VMs. Alternatively, you can specify a list of VMs on the command line, e.g. backupvm DC01. To check which VMs will be backed up use the -l flag:

[root@xenserver01 ~]# sh XenServer/backupvm  -l
Reading ~/backupvm.conf

To cleanup old versions (i.e. use the number of generations configured and delete any older ones), run sh XenServer/backupvm -c

Configuring email reports

To send email reports, you need to specify the SMTP server to send the emails via. This can be specified in 3 ways:

  • Configure email alerts on the pool in XenCenter (backupvm will use the same server)
  • On the command line with the -o option
  • In your backupvm.conf file with the mailhub setting

To email a report, use the -i option (you can also use the emailto setting in a backupvm.conf file, but this will not allow you to view progress when running a manual backup). The -p option to add date/time stamps to each line is also useful.

For a manual run, if you could use:
backupvm -i -p

Copy backups to another XenServer not in the same pool

  • Install the scripts on the other XenServer rather than the main pool.
  • Configure the VMs to be backed up in the same way as usual (vms and backup options in backupvm.conf).
  • Set action to copy
  • generations is the number of copies of a VM to keep (to keep all versions, set to 0 or don't set)
  • Set server to IP address of pool master in main pool
  • Specify XenServer logon details for the main pool (probably root) using username and password options
  • sr does not need to be set as it will import into the default Storage Repository on the backup server
  • Finally, you must specify a temporary storage location to be used on filesystem of the backup server with exportdir. Generally this will probably a separate logical drive on the local RAID controller. This should have an ext3 filesystem on it created with mkfs and be automounted in /etc/fstab (exact procedure for doing this is beyond this document as hardware will vary).

Example backupvm.conf:


Example list of mounts:

/dev/cciss/c0d0p1 on / type ext3 (rw)
none on /proc type proc (rw)
none on /sys type sysfs (rw)
none on /dev/pts type devpts (rw)
none on /dev/shm type tmpfs (rw)
/opt/xensource/packages/iso/XenCenter.iso on /var/xen/xc-install type iso9660 (ro,loop=/dev/loop0)
/dev/cciss/c0d2p1 on /staging type ext3 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)

Exporting as .xva files to backup storage

  • Mount the backup storage on a given location (could be local storage formatted as ext3) or an NFS export
  • Configure the VMs to be backed up in the same way as usual (vms and backup options in backupvm.conf).
  • Set action to export
  • sr does not need to be set
  • Do not set generations
  • Specify location to export to with exportdir
© Copyright Precedence Technologies 1999-2019
Page last modified on April 29, 2019, at 10:40 AM by sborrill