Currently, we are using a combination of Puppet and Foreman to deploy virtual machines to our environment. Allowing Foreman to deploy the VM guest and then having PXE install the OS is awesome, a great hands-off system after the initial setup and configuration is done.

One of the limitations of Foreman, however, is it only deploys the guest as an image file in RAW format or QCOW2 format. I wanted a solution to backup the guest without pausing or stopping it, while at the same time not requiring any changes with how Foreman deploys our VMs. I solved this by using the ‘qemu-img’ command.

WARNING

Just a heads up, we no longer use this tactic because it’s against best practices. Execute at your own risk.

Learn How:

1.    Create a snapshot of the running VM, named “date”.  This will not pause or shutdown the guest.

qemu-img snapshot -c “date” /var/lib/libvirt/images/beta-test-disk1

2.    Create a usable disk file from the snapshot.

qemu-img convert -f qcow2 -O qcow2 -s “date” /var/lib/libvirt/images/beta-test-disk1 /var/lib/libvirt/images/beta-test-disk1-“date”

3.    Remove the snapshot.

qemu-img snapshot -d “date” /var/lib/libvirt/images/beta-test-disk1

 

Now you have file/var/lib/libvirt/images/beta-test-disk1-“date” to copy to a new location or archive. Personally, I take the file and bunzip2 it to conserve space.

A few items to consider are that this works on a per disk level, so if your guest has multiple disks, you’ll need to snapshot per disk. I use /usr/bin/virsh domblklist “vm name” to help determine the disks attached and their actual file name. Secondly, if you’re running a database, index, or something similar, you’ll need to make sure to flush any info out of RAM to the disk.

Overall, this process is easy to use, very flexible, has almost no downtime with the part of the guest.

 

Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInShare on RedditBuffer this pagePrint this pageEmail this to someone

Related Posts

Related Topics & Tags: General Information Quick Tips

About Chris Sheaves

I am the VP of Products at SmartFile. I'm tasked with managing and overseeing the evolution of SmartFile's products and solutions. I'm great at listening to our customers and translating their wants and needs to our engineers. I also oversee all IT operations and infrastructure.

4 thoughts on “KVM Snapshot without LVM”

  1. Never use “qemu-img snapshot” on the image of a running VM! It’s bound to corrupt your image sooner or later. Images files may only be opened from one read-write process at the same time.

    The correct way of taking a snapshot while the VM is running is from within qemu. Depending on whether you use libvirt, you should just use libvirt’s functionality to take a snapshot, or you can use the monitor console of the running qemu process.

Leave a Reply

Your email address will not be published. Required fields are marked *