WIP Add KVM host backup recipe

Add a recipe that configures scripts for live backups of VM images via
libvirt and borg.
This commit is contained in:
Râu Cao
2022-10-18 18:45:17 +02:00
parent 6d50a32aca
commit a3844b7ef6
3 changed files with 81 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
#!/bin/bash
# GENERATED BY CHEF
# DO NOT EDIT
set -e
REPOSITORY=$BORG_REPO
echo "Starting backup of VM: $1"
echo "Dumping domain XML to /root/backups/vm_meta/$1.xml"
virsh dumpxml --migratable $1 > /root/backups/vm_meta/$1.xml
virsh snapshot-create-as --domain $1 \
--name hotswap.qcow2 \
--no-metadata \
--atomic \
--quiesce \
--disk-only \
--diskspec vda,snapshot=external
borg create -v --stats \
$REPOSITORY::$1_$(date +%F_%H-%M) \
/var/lib/libvirt/images/$1.qcow2 \
/root/backups/vm_meta
echo "Pivoting base image back to original"
virsh blockcommit $1 vda --pivot --base=/var/lib/libvirt/images/$1.qcow2
echo "Removing snapshot image"
rm /var/lib/libvirt/images/$1.hotswap.qcow2