I have created multiple KVM VMs using QCOW2 images.
Each VM has its own qcow2 file and is not based on any backing file.
My question is specifically related to snapshots of QCow2 images on these running VMs.
If I run the following command on a running VM :
qemu-img snapshot -c backup /vms/vm10001.qcow2

Will the above command harm the running VMs filesystem ?
My intention is to then convert the snapshot into a qcow2 image using the following :
qemu-img convert -s backup /vms/vm10001.qcow2 /vms/output.qcow2

I am unable to use the "virsh" commands and hence I am trying to figure out a way to do my task with qemu-img

Answer / Update 1 :
Ok, so I tested this on several of my test VMs and the above is not possible. You cannot run qemu-img snapshot on a live VM without pausing it.

The only way to do it on RHEL base Nodes is to use :
virsh snapshot-create <dom>

The above will save the VM state and internally then call qemu-img snapshot -c. However this can take some time which brings me to my second question

Question 2 : virsh snapshot-create <dom> --disk-only --atomic is not supported on base Nodes which are RHEL types (including RHEL 7) because the qemu-kvm is very old.
So the only option is to use virsh snapshot-create <dom> which is kind of slow.
Is it possible to do the following :
virsh suspend <dom>
qemu-img snapshot -c backup /vms/<dom>.qcow2
virsh resume <dom>

The above operation seems to be much faster than snapshot-create

Answer / Update 2 :

Even the above question 2 is not possible. After doing a lot of research I have concluded the same.

Question 3 :

Is there any method to create a snapshot for an online VM having a Qcow2 disk on a RHEL 6 / 7 base node and then make a backup of the snapshot for restore later on ?

  • Ok, so I tested this on several of my test VMs and the above is not possible. You cannot run qemu-img snapshot on a live VM without pausing it. May 16 '15 at 11:09
  • The old version of qemu on EL7 was one of the primary reasons I switched to Fedora hypervisors. May 16 '15 at 15:21
  • So is there no possible way to backup qcow2 live VMs on RHEL 6/7 ? May 16 '15 at 18:23
  • 1
    are you using qemu-kvm or qemu-kvm-rhev? The latter has all the fancy upstream stuff backported
    – dyasny
    May 18 '15 at 17:10
  • I am using qemu-kvm. I had installed the qemu-kvm-rhev from oVirt and checked the qemu-img utility to see the new params. The new Params were the same. So I assumed that it really wasnt different. Will installing qemu-kvm-rhev require any update in domain configs to update the qemu-kvm path ? May 20 '15 at 9:04

This not an exact answer but will show you the way.

We are using linux KVM for a long time. In old days qcow2 did not support snapshots. In our first KVM host we did not want to use LVM snapshots and because of that we could not take live backups.

Then we found Linux Hot Copy Tools.

Using this tool; we could freeze whole host filesystem and copied qcows to external disks with a custom backup script.

Our backup script was something like this;

# Mount Usb
mount /dev/sdb1 /USBDISK
# Mount file system as ro to temp folder
hcp --read-only --mount-point /SNAPSHOT /dev/md1
# Copy files out
# Stop Hot Copy
hcp --remove /dev/hcp1
# Remove Usb
umount /USBDISK
  • I read this and HCP requires a kernel module to be loaded. This will create a snapshot for the entire drive I believe. Jul 15 '15 at 7:53
  • @user1066991 yes you need to load kernel module once. And also you are correct about snapshot too. Jul 15 '15 at 16:04
  • The problem with this is that it will create a snapshot of the entire partition. Lets say we have 10 VMs of 100GB each. I want to backup 1 VM at a time. This will result in a snapshot which will last for all files in the partition rather than the QCOw2 file of the VM alone. Dont you think that the snapshot data can run out of space in this case. Jul 16 '15 at 12:19
  • In our situation there were 30+ active qcow files active. While backup script was running, in 4 hours period we copied ~200GB everynight @15MBps (to a slow USB) and our max snapshot usage was 25 GB on the host drive. Also hcp checks for free space on host drive (while snapshot active) and if free space drops below a predefined percentage hcp stop snapshot. Jul 16 '15 at 17:03
  • from man hcp; OPTIONS -q, --quota specify free space quota for change blocks storage (default is 5%). If your changed blocks storage device has less than or equal to this percentage of free space the Hot Copy will be aborted. Jul 16 '15 at 17:07

my experience with KVM is actually quite limited but being in a very similar situation, that's what worked for me:

first of all I do a backup of the config for the VM named MACHINE:

# virsh dumpxml MACHINE > /path/to/configfile.xml

Then I suspend the VM named MACHINE to prevent corruption in newly created machine:

# virsh suspend MACHINE

Next I create a snapshot named MACHINE-BAK.qcow2 from the VM named MACHINE using qemu-img command, even if normally is used to convert among formats:

# qemu-img convert -O qcow2 /path/to/MACHINE.qcow2 /path/to/MACHINE-BAK.qcow2

Next I resume normal operativity for the original VM named MACHINE:

# virsh resume MACHINE

Applying these simple steps in a script that runs via crontab automation, I'm able to obtain a periodical full backup of a running VMs with minimal downtime (depending on the size of the original VM, since as said above, it's better to susped the original VM while duplication)

  • The OP explicitly stated that he cannot use the virsh commands.
    – Binarus
    Oct 20 '20 at 21:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.