Web lists-archives.com

KVM snapshot management




I'm running a VM host server with Debian/Stable on AMD64.

I recently converted an important VM over to qcow2 so I could take advantage of snapshots. I don't think I need to be able to revert back more than a week, so I thought that naming each snapshot with the day of week number would be reasonable as it is easy to implement and to understand which day it is for. I established a bash script to be run from /etc/crontab to handle this.

After shutting down the VM, I delete the previous week's snapshot, which should be the oldest. My understanding is this merges it back into the base image while the new snapshot that I create next is now 6 snapshots away from the base. I think this gives me the ability to revert back up to a week if needed.

Since the snapshots are named using the DOW, the new snapshot has the same name as the one I just deleted. The names also cycle over a period of a week.

Is my understanding of the way snapshots work correct and is my approach reasonable?

The core part of my script is below. This is working in that it does what I described above WRT handling snapshots (for the first week, of course, the snapshot-delete fails since there isn't one).

virsh shutdown $VM
state=$(virsh list --all | grep " $VM " | awk '{ print $3}')
while ([ "$state" != "" ] && [ "$state" == "running" ]); do
  sleep 10
  state=$(virsh list --all | grep " $VM " | awk '{ print $3}')
done;
DOW=$(date +%u)
virsh snapshot-delete    --domain $VM --snapshotname ${VM}S$DOW
virsh snapshot-create-as --domain $VM --name ${VM}S$DOW
virsh start $VM