I want to back up a virtual machine image when I went to the directory where the images are stored /var/lib/libvirt/images/ I found one .img file, the rest were .qcow2, unlucky the virtual machine I want to back up is the one with the .qcow2 image. I'm not too sure what type of format that is also I'm not too sure if I compress this format if it would back up all of my data. Are you familiar with format, is my data stored in the .qcow2 file?


To backup a qcow2, you have to quisece the filesystem (if it's running and qemu-guest-agent is running on the guest) and convert it to raw.

# qemu-img convert -O raw qcow2image.vm convertedraw.vm

When you want to restore it, you have to convert it back. Reverse order, changing the -O switch's value.

# qemu-img convert -O qcow2 convertedraw.vm qcow2image.vm

If the VM is running and you want to take a backup, these are the steps:

  1. Freeze the vm.
  2. Create a snapshot.
  3. Thaw the guest.
  4. Take a backup from the snapshot.

Like so.

# virsh domfsfreeze vmname
# qemu-img create -f qcow2 -b qcow2image.vm qcow2.snap
# virsh domfsthaw vmname
# qemu-img convert -O raw qcow2.snap backup.img

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.