diff --git a/libvirt-zsh-backup.sh b/libvirt-zsh-backup.sh index 2691df6..3c9ea70 100644 --- a/libvirt-zsh-backup.sh +++ b/libvirt-zsh-backup.sh @@ -39,5 +39,34 @@ for disk in $VMDISKS do DISKSPEC+="--discspec $disk,file=/srv/snapshots/$VM/$VM-$disk-$SNAPNAME.qcow2,snapshot=external " done -echo $DISKSPEC + +virsh snapshot-create-as --domain $VM --name $SNAPNAME --quiesce --atomic --disk-only $DISKSPEC > /dev/null +if [ $? -ne 0 ] +then + echo "VM snapshot creation failed" >&2 + exit 1 +fi + +zfs snapshot "$SRCZFS"@"$SNAPNAME" +if [ $? -ne 0 ] +then + echo "ZFS snapshot creation failed" >&2 + exit 1 +fi + +for disk in $VMDISKS +do + virsh blockcommit $VM $disk --pivot --active >/dev/null +done + +VMDISKS=$(virsh domblklist $VM | egrep vd.) +for disk in $VMDISKS +do + if [[ $disk == *"snapshot"* ]] + then + echo "Snapshot deletion failed for $disk" >&2 + fi +done + +zfs send "$SRCZFS"@"$SNAPNAME" | pv -L 500M | ssh $DESTHOST sudo zfs recv -F $DESTZFS