#!/bin/bash SRC=/mnt/ DEST=/mnt/ mv $DEST/-clone.qcow2 $DEST/-clone.qcow2.old virsh undefine -clone virsh dumpxml > $DEST/.xml virsh shutdown sleep 60 virt-clone --original --name -clone --file $SRC/-clone.qcow2 virsh start if [ -f $DEST/-clone.qcow2.old ]; then rm -f $DEST/-clone.qcow2.old else echo "The file $DEST/-clone.qcow2.old does not exist!" fi echo "Compressing the disk file by creating a new one from it." qemu-img convert -c -O qcow2 $SRC/-clone.qcow2 $DEST/-clone.qcow2.smaller rm $SRC/-clone.qcow2 mv $DEST/-clone.qcow2.smaller $DEST/-clone.qcow2