Bacula Community has a great generic plugin that uses FIFO to backup basically any application without having first to dump or export data on disk.
The script bellow is supposed to generate (dynamically) bacula-dir.conf configuration lines, for the backup all running VM of a Xen host using bpipe.
In this example, the restore of the VM export file is done to a fixed folder (/mnt). This can be changed or even altered to a Xen import command.
If you need or want to know more about bpipe, I do have nice inexpensive video classes with several detailed examples: URL with coupon code.
#!/bin/bash
#
# /etc/bacula/scripts/bpipe_xen.sh
#
# Script to generate Bacula FileSet bpipe syntax configuration in order to backup
# all running Citrix Xen VM.
#
# Autorhip: Heitor Faria (Copyleft: all rights reversed).
# Tested by: Elias Pereira
#
# It must be called at the FileSet INCLUDE Sub-resource, used by the job that
# backups Citrix Xen machine that must have a installed Bacula Client, like this (e.g.):
#
# Plugin = "\|/etc/bacula/scripts/bpipe_xen.sh"
#
for UUID in $(xe vm-list power-state=running is-control-domain=false | grep uuid | cut -d: -f2- | tr -d )
do
VM_NAME=$(xe vm-param-list uuid=$UUID | grep -i name-label | cut -d: -f2- | tr -d )
SNAP_UUID=`xe vm-snapshot uuid=$UUID new-name-label=$VM_NAME.snps`
xe template-param-set is-a-template=false uuid=$SNAP_UUID
echo "bpipe:/var/$VM_NAME.xva:xe vm-export vm=$SNAP_UUID filename=:dd of=/mnt/$VM_NAME.xva"
done
For this Job it may be also a good idea to have a post script (ClientRunAfterJob directive, bacula-dir.conf Job resource) to delete all Xen VM snapshots. At this time the machines are already exported to backup:
#!/bin/bash
#
# /etc/bacula/scripts/after_job_xen_snapshots_delete.sh
#
for i in `xe snapshot-list --minimal | sed -e 's/,/ /g'` ;
do
xe snapshot-uninstall force=true uuid=$i ;
done