I have a Xen server dom0 with a number of guests installed and am struggling to find an easy way to manage backups from the dom0 side.

  • Guest scripts: Of course I could run backup scripts on each of the guests but wish to avoid that if possible from a management point-of-view. Ideally I would also like to be able to backup disk images themselves which, along with config, could then be restored directly onto another Xen dom0 if required, along with perhaps a file backup of certain directories.
  • rsync of /var/lib/libvirt/images: I have tried a simple rsync of the image files in /var/lib/libvirt/images/ with the domains shut down but there is a problem - the disk images try and copy at their full available size (the size they are available to grow to). So this means each image tries to copy at 250Gb rather than the actual around 2.5Gb (e.g. the size shown by ls -l not the size [used] shown by du).

There are a number of solutions and scripts online but these all seem quite old and seem to be based on disks being LVM devices and so found in /dev/virtual/NAME-disk, whereupon they can be copied and then mounted, and then backed up using rsync. This does not appear to be how my system is configured.

I see a could of potential solutions if they're possible (as I mentioned ideally I would like to backup an image file and also do a file-level backup of certain directories on the VM as well so perhaps a combination of these).

  1. Shrink Image File: Can I copy the image file and then shrink it to it's actual used space? I could then rsync this and delete the temporary file.
  2. Copy at actual size: Copy the image file somehow at it's actual size and then if needed recreate the size attributes on another dom0?
  3. Mount Image File: Somehow mount the image file directly? I see there are ways to convert it to an LVM image but not sure if this is the only way (and I'm happy with the use of image files for the normal operation of the domain guests).

Thanks in advance and hope it's clear enough.


To me, backing up disk images makes more sense here. From the backup script perspective, it shouldn't really matter if the VDIs are file- or LVM-based, you should be able to backup them the same way, by only changing paths. Moving to LVM, though, may give you a serious performance gain, especially if you employ raw (not VHD based) VDIs.

To avoid entire sparse files being transferred every time, further modify scripts to pipe data through a packer (gzip being a fine solution). This way, even reading a VDI file in its full size will give you a compact output. This may be hard to achieve with rsync so use other means to transfer the data to backup location (ie. ssh with shell redirection).

To reduce downtime, in case of LVM SR (not sure with image files), you can also enhance your script so it will take a snapshot of the VM prior to backing it up. It can then backup from snapshot storage, so it will provide consistent data without VM being blocked from start. Taking snapshot usually takes as few as few seconds. Snapshot VDIs can also be mounted on dom0 to backup individual files, the only problem being VHD format being used (again, go with LVM and raw VDIs).

  • Zip certainly does make a difference (250Gb -> 2Gb) but it is very slow but not a huge problem. I think this will be the image backup solution, but would still ideally like to be able to mount the .img file as well so can just backup critical files also. – Dave Nov 22 '15 at 16:13
  • Check the modified answer. – sam_pan_mariusz Nov 22 '15 at 18:39
  • Thanks - for the moment I'm happy with the VHD format for various other reasons so I think I'll stick with: (a) copying .img file, (b) zipping file, (c) rsync zip files. If I need file-specific backup then I'll run a specific file backup on the guest. Thanks again. – Dave Nov 23 '15 at 13:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.