Filippo Zanardo's Blog

to blog or not to blog

0 downtime snapshot based XENServer 5.5 backup script

with 19 comments

Check this new better version of the script

Ok guys based on this script i made mine with some more features.
Basically i split the configuration file out of the script and added some new features:

automount: if set to true script try to mount the backupdir specified in mountcommand at start and umount at end, else no action taken and u have to mount dir manually

subfolder: Set to true to create a subfolder in the store for each backup based on vm name

versioning: Set to true to let the script manage to delete the backup older than a certain day or number or hours

and i rewrite the message so they are now more “human” readeable.

The usage it’s the same except u have to pass the path to the config file to the script like:

perl /path/to/ /path/to/config.txt

U can download the file here

Unzip in a folder and read and modify the configuration file (basic explanation is written in), i put also in the config file message’s string so it’s easy to translate in your preferred language, i added also the elapsed minute time of each backup.

Next remember to modify the SendEmail script changing the “server” line at line 65, to send notification mail.

## Network
“server” =>’’,
“port” => 25, ## Default port
“alarm” => ”, ## Default timeout for connects and reads, this gets set from $opt{‘timeout’}

and at line 54 hostname:

“hostname” => ‘’, ## Used in printmsg() for all output, and in SMTP EHLO.

Next call in a cron job or manually the script and enjoy.

Remember to put in the skip variable the uuid of the control domain on host and other vm that don’t need to backed up!

Don’t remove the “\” near @ cause it’s needed for the sendEmail script, so the string should looks like “mymail\”

Comments for bug, wish feature etc etc…

Based on todo list on the main page i will add other feature when i have time!


Check this new better version of the script


Written by pipposan

December 9, 2009 at 17:38

19 Responses

Subscribe to comments with RSS.

  1. Filippo, great Job !!

    I have a doubt in the config file. There’s a configuration to skip the vms that i don’t want to backup, if i have more than one VM, I add in the same line, with “,” or a have to creat new lines with the UUID ?

    Tks !


    January 12, 2010 at 20:43

    • thanks πŸ™‚
      it’s simple in the config file use this line:

      #uuid of the machine to skin in the backup, use xe vm-list to get yours
      #add chunks of uuid to skip backing up of a specifc vm
      #control domain (dom0) should be added to this list!!
      @skip = (‘c1e05f42-b2bf-4006-bdd8-e5bec42692bc’.’sfasfasdfasdf-dfasf…..’,’fdasfasfasdfasfasdfasdfasdf’);

      basically u can add uuid obtained by the command “xe vm-list” and add it in the @skip variable separated by “,”.

      @skip = (‘c1e05f42-b2bf-4006-bdd8-e5bec42692bc’,’sfasfasdfasdf-dfasf…..’,’fdasfasfasdfasfasdfasdfasdf’);

      also remember to put in this line the uuid of the host machine.


      January 13, 2010 at 16:17

  2. Ok, perfect.

    I tested it in the morning, with “,” before seen this reply, and had success, only the VMs that i let out made backup, perfect.

    One more doubt, in the end of the backup some more problems, let me see if you could help me one more time.

    Here is the error:

    sh: command substitution: line 0: unexpected EOF while looking for matching `”
    sh: command substitution: line 1: syntax error: unexpected end of file
    Jan 13 11:59:56 sendEmail[25522]: Error: “-” is not a recognized option!

    And no email was sent me.

    I reviewed the configuration sereval times, and did not found errors.

    Can I take the snapshot in a different location or only in the Storage Repository that the VM is located on ?

    Tks again ! (sorry my bad english :o)
    Cheers !


    January 13, 2010 at 18:58

    • You can skip this error is an error from the sendemail script that i didn’t fix it yet.
      But mail was sent succesfully also with the error.
      Remember to change in the sendEmail script this 2 line to your smtp server:

      ## Network
      “server” =>’’,
      “port” => 25, ## Default port
      “alarm” => ”

      and the line after if is authenticated.

      You can take snapshot in any location u want, i mean u can mount a nas a san or a usb disk in your host domain and then the snapshot is created phisycally on it.
      for example i use a nas for the backup and i mount like:
      mount -t cifs //myip/myfolder /my/backupdir

      and then snapshot is created on the nas.

      I hope it’s clear enought my explanation πŸ™‚ (my english is bad too :p )
      if not ask me i try to help.



      January 13, 2010 at 20:03

  3. […] is a simple script check this one is […]

  4. Hey Filippo ! Good Afternon !

    One more doubt, if i have a VM with 2 disks (one atacched), it i’ll backup all the disks or only the first ?

    c:\ – windows instalation
    d:\ – data files – atached disk.

    Ths a lot !


    March 22, 2010 at 18:47

    • The email function worked !! Perfect.

      It does the coalesce-leaf automatically after the snapshot ?

      Tks !

      I’m in final test phase ! :o)
      sorry for the inconvenience !


      March 22, 2010 at 21:06

      • Yes the snapshot make the backup of all the disk in the vm.
        For coalasce-leaf at the moment is not implemented yet, but if u install xen server update 2 the space i think is reclamed automatically, btw i add it to the script when i have some time.



        March 23, 2010 at 18:37

  5. Works well except most of the times, it doesn’t remove ‘-BACKUP_VM’ snapshots in cases if VMs have multiple or larger VDIs and as a result it starts backing up those snapshot VMs when script runs next time.

    Though I see a warning in logs that could have caused this.

    The following items are about to be destroyed
    VM : cba2c02f-3396-5753-6417-af18500fcabf (TestVM-backup_vm)
    VDI: c1a2faea-5934-4719-b7b2-901b6701917f (0) ** WARNING: disk is shared by other VMs
    All objects destroyed


    April 14, 2010 at 17:14

    • Can you post your configuration?
      You use a iscsi or whatever

      i will try to reproduce the error and fix the script.


      April 15, 2010 at 12:03

  6. The download link isn’t working.


    April 20, 2010 at 16:01

  7. man, the script send mail not work… any configuration special?
    thanks for nice script


    May 6, 2010 at 14:07

    • no as long you modify around line 65 in the script “server” , “port” etc etc
      if some warning display just skip mail should send correctly, btw i didn’t made the sendmail script i will use another when i have time.


      May 7, 2010 at 09:10

  8. Hi Filipo

    It seems very interesting your script, but before to implement, may I ask you something? …

    could you test the performance impact over VMs while they are taking backup?


    May 12, 2010 at 21:36

  9. Ithaia,

    The backup process itself is very slow and quite moderate which obviously doesn’t cause any load on the node. I’ve it running for like more than 5 months and backing of 5 VMs, each weighing 20 Gig takes four hours to complete.


    May 13, 2010 at 09:24

  10. Bassu speak for me.
    Btw u can schedule the backup in the night or when the load on the vm is not so high.


    May 13, 2010 at 12:05

  11. I’m new to XenServer. I guess that I need to install the scripts on the Xenserver itself. Am I correct?


    September 25, 2010 at 15:08

    • hi, u have to run on xenserver, you don’t have to install anything.


      September 27, 2010 at 14:08

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: