Restoring a KVM Backup with Virt-Manager

So in the previous tutorial I showed you how to create full backups with virt-manager that you can store someplace safe to be restored in an emergency. In this tutorial I’m going to show you exactly how to restore a VM.

I’m going to delete and test restore the same VM that I backed up in the previous tutorial - my Fedora VM. Here it is shut down and ready to go bye-bye.

virsh list --all
 Id   Name          State
 1    ActualArch    running
 -    archlinux     shut off
 -    endeavoros    shut off
 -    fedora        shut off
 -    freebsd13.1   shut off
 -    Gentoo        shut off
 -    manjaro       shut off
 -    ubuntu22.04   shut off
 -    win11         shut off

For demonstration purposes, I will be deleting this VM on purpose, but you can’t remove a VM using this method when you’ve got snapshots of that VM. So we’re going to check and see if there are any snapshots of the Fedora VM:

virsh snapshot-list fedora
 Name       Creation Time               State
 05292023   2023-05-29 15:18:00 -0400   shutoff

Delete the snapshot with the following command:

virsh snapshot-delete fedora 05292023

The response takes a few minutes depending on the size of the VM, but after a moment:

Domain snapshot 05292023 deleted

OK now we can delete the actual virtual machine. We do that like this:

virsh undefine fedora --remove-all-storage
Domain 'fedora' has been undefined
Volume 'vda'(/mnt/D0F0D4BFF0D4ACCA/virtual machines/fedora.qcow2) removed.

To get it back, we go to our backup location, and redefine the XML file for our VM like so:

virsh define fedora.xml
Domain 'fedora' defined from fedora.xml

That took care of the metadata, but we still need the actual backup file. We simply copy the qcow2 file from our backup location (in my case, one of my external hard drives) to the working directory where our virtual machines are located. Remember to replace my directory path here with your own, along with your own filename.qcow2 :

(Note: This will not recover snapshots. I would make a snapshot right after you verify that your restored VM is working properly.)

cp /media/doc/6b9ba500-17ff-4042-b226-488bca206f64/fedora.qcow2 /mnt/D0F0D4BFF0D4ACCA/virtual\ machines/

Depending on the size of the VM, this could take a while. (in my case, the VM had a 500G HD so it took awhile indeed). When it returns, you should be able to start up and test your newly restored virtual machine :

virsh start fedora

Once it boots, you should be able to access your VM as if nothing ever happened. Thanks for coming along with me while I test restored one of my backups! I hope this helps someone.


@Doron_Beit-Halahmi ,
Would I be right in assuming that if I make a VM using the qemu command ( instead of using virt-manager) , then there is no metadata… it is given in the options on the qemu command used to start the VM.
So a VM made with qemu could be backed up just by saving the qcow2 file.
That would explain why virt-manager can not run a qcow2 file made with qemu. I have been puzzling about that.


I would assume that to be correct… The XML file is the metadata for virt-manager (how big the disk is, processor specs, memory, etc) … so its required for virt-manager to know how to start the qcow2 file.

So while its true that a QEMU VM can be backed up by simply copying out the .qcow2 file, I’m assuming it wouldn’t work with virt-manager unless you had an XML file defined with the metadata in order for virt-manager to use that qcow2 file. I believe you can only copy the qcow file when dealing with hypervisors like proxmox, but I could be wrong.


It does work in the other direction. A qcow2 file created with virt-manager is able to be run with a qemu command.
That supports what we have concluded, qemu simply ignores the metadata and set up its own.

I have found that the display window you get with qemu + spice has some limitations, compared to the display you get with virt-manager. It would seem that virt-manager does not use any of the qemu display options, but instead sets up its own inbuilt display function.

Thanks for the backup and restore examples. I need to learn about virsh… have not used that.