Backup KVM Máquinas Virtuais Quente Online com o bpipe Bacula

Este script pretende fazer backup de máquinas virtuais QEMU/KVM/libVirt. Este requer o KVM 2.1+, pois ele usa o modo de bloqueio em tempo real. Isso significa que os dados no disco instantâneo são revertidos para o original ao final do backup.

Script Bpipe

#
# FileSet Include (bacula-dir.conf)  
#
#    Plugin = "\|/etc/bacula/kvm_bpipe.sh"
#
#
DOMAIN=`virsh list --all | tail -n -2 | head -n -1 | awk '{print $2}'`

for d in $DOMAIN; do

  TARGETS=`virsh domblklist "$DOMAIN" --details | grep ^file | grep -v cdrom | awk '{print $3}'`
  IMAGES=`virsh domblklist "$DOMAIN" --details | grep ^file | awk '{print $4}'`

  for t in $TARGETS; do
    virsh snapshot-create-as --domain $DOMAIN --name backup --no-metadata -atomic --disk-only --diskspec $t,snapshot=external >/dev/null
  done

  for t in $IMAGES; do
    NAME=`basename "$t"`
    echo "bpipe:/mnt/$NAME.bkp:cat $t:dd of=/tmp/$NAME.bkp"
    echo "bpipe:/mnt/$NAME.xml.bkp:virsh dumpxml $DOMAIN:dd/tmp/$NAME.xml.bkp"
  done
done

Script ClientRunAfterJob

#
# KVM Backup Job (bacula-dir.conf)
#
#    ClientRunAfterJob = "/etc/bacula/kvm_commit.sh"
#

DOMAIN=`virsh list --all | tail -n -2 | head -n -1 | awk '{print $2}'`

BACKUPIMAGES=`virsh domblklist "$DOMAIN" --details | grep ^file | awk '{print $4}'`
for t in $TARGETS; do
    virsh blockcommit "$DOMAIN" "$t" --active --pivot >/dev/null
    if [ $? -ne 0 ]; then
        echo "Could not merge changes for disk $t of $DOMAIN. VM may be in invalid state."
        exit 1
    fi
done

Fonte

https://gist.github.com/cabal95/e36c06e716d3328b512b

Disponível em: pt-brPortuguês enEnglish (Inglês) esEspañol (Espanhol)

Deixe uma resposta

Fechar Menu