xapi-back Simple Xen Backup Tool

xapi-back is a simple backup tool for XenServer or XCP – xen hypervisors using xapi toolstack.   xapi-back is a command line tool with simple and clear interface (command + options). Tool is written in python.

Features

  • simple command line interface
  • can backup VMs from multiple hosts
  • backup of live VMs (creates temporary snapshot of VM)
  • can combine several backups into one batch (which then can be scheduled in cron)
  • keeps x previous backups (can be set in config file)
  • backups are gziped to save space
  • ideal for small scale backups to USB disk
  • and of course free and open source

Install

Source is on github.

To install on new system run as root (assuming pip is already installed):

pip install git+https://github.com/izderadicka/xapi-back.git#egg=xapi-back

This will install xb tool and create sample configuration file in /etc/xapi-back.cfg or ~/.xapi-back.cfg if run as non root user. (For security reasons it better to have this file in your home directory with 0600 access – you can copy it or install as non root user).

Usage

Edit configuration file ~/.xapi-back.cfg or /etc/xapi-back.cfg (if you have both the one in home directory is used), file has JSON syntax.  Change:

  • your hosts
  • backup directory root:
  • number of backup copies to keep:
  • compression – backed-up VM image can be either uncompress (“none”), or compressed in xb (“client”), or compressed on XenServer (“server”) ( in dom0 as part of export process).

    WARNING: This is pretty important decision and must not be changed afterwards, when storage_root already contains some backups, because modes are mutually incompatible!
    “client” – is a default mode and usually good unless you require some special scenario covered by other two. Backup speed is limited by gzip speed or slow network. Compression is offloaded from Dom0, which is usually good thing,
    “none” –  it’s  good, if you have fast disks and network and you do not care about disk space, backup is not limited by gzip, but only by I/O speed.
    “server” – compression in done in XenServer Dom0. It’s good if you have slow network (making backups over Internet for instance).
  • Compression level 0 (no compression, but gzip still calculates checksum) – 9 (best compression,  but slowest – level 9 is about 4 – 5 times slower then level 1 and additional space gained is not so significant –  usually 10 – 15% ). It works only for “client” compression:
  • log file (optional):
  • Email log – there is possibility to send session log after each xb run – this section in config file can specify details:

     

Test then you can connect to your hosts:

Next try this command:

You see list of all available VMs with information about their backups.

There are several  possibilities how to backup VM:

manual – single VM

Backup speed is basically limited by speed of gzip compression, which can be 30-60MB/s on common machine for level 1 (and can be much slower for highest levels). So if you are really concerned about speed you can turn off compression in configuration.  Also there is –insecure switch, which will force http connection with server for backup transport – theoretically it can speed up backup a bit, because you are not encrypting transport, but in practice I did not mention notable difference – TLS encryption is pretty fast .

If there are VMs with same name you’ll receive error about non-unique name, you need to then specify VM with --uuid argument –  usually first few character of UUID is enough.

manual –  batch

Add VMs to batch:

And run batch:

xapi-back can backup of running VMs – it creates a temporary snapshot for backup purpose, (which is basically a template in XenServer – so you should take this in account when restoring).  If you’d rather like to shutdown machine before backup and do a cold backup use –shutdown option in backup command.

Backups can be also easily scheduled via cron (that was an idea behind batches –  to create different batches, which can be scheduled with different periodicity) –  see sample cron script:

To restore a VM use:

It’ll restore  last backup of VM under same name  on given host (or snapshot name, which is Temp. backup of …). There are some additional restore options, check xb restore -h. Restore is done to default Storage Repository (SR),  unless you specify specific SR with --sr_id  argument.
If you are restoring snapshot and you need to restore as VM (not as template) use --as-vm parameter.

You can also  list SRs available on the host with xb srs --host host_name.

Restoring other then latest backup has to be done outside the tool – just find correct file (under backup root in directory with VM name) ,  gunzip it and use xe vm-import or other tool to import VM.

 

4 thoughts on “xapi-back Simple Xen Backup Tool”

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

My Digital Bits And Pieces