Home How To's backup all KVMs

backup all KVMs

backup all KVMs

An easy one, to backup all KVMs in .qcow2 format, regardless of their current running state. We are backing here: All KVMs, which have changed during the past 24 hours. We skip not used or idle images

What we do here? We just unset/delete the VMs for time of backup and restore them immediately after, to avoid corruption. We keep 5 backups of each as maximum

d="$(date +"%d-%m-%Y")"
mkdir $workdir/$d
or DOM in `virsh list --all | tail -n +3 | awk '{print $2}' | sort -u`
virsh dumpxml --security-info $DOM > $mydir/$DOM.xml
virsh undefine $DOM
virsh blockcopy $DOM hda $mydir/$DOM.qcow2 --wait --finish --verbose
virsh define $mydir/$DOM.xml
find /var/lib/libvirt/images -mtime +1 -exec cp "{}" $mydir \;
cd $workdir;
# keeping 5 sets ls -dt */ | tail -n +6 | xargs rm -rf
ls -dt */ | tail -n +4 | xargs rm -rf

It has been read 204 times

IT Bizz.Net Tags:

#univention #univention ucs #univention corporate server ucs #univention vietnam #univention partner vietnam #vietnam open source #foss #devops #data science #security #network security #network security vietnam #open source