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.