So if you like to mess around like I do, you’re probably familiar with the idea of virtual machines. I like to use a program called virt-manager under Linux to create and work in VMs. It’s quick and easy, and gets the job done. But you’re probably wondering how you backup said VMs. I’m here to show you.
First list the VMs you currently have available to make sure they’re shut down :
virsh list --all
Id Name State
------------------------------
52 ActualArch running
- archlinux shut off
- endeavoros shut off
- fedora running
- freebsd13.1 shut off
- Gentoo shut off
- manjaro shut off
- ubuntu22.04 shut off
- win11 shut off
In my case I’ll be backing up the “fedora” VM. Do this to shut it down :
virsh shutdown fedora
And repeat the listing to verify that it worked:
virsh list --all
Id Name State
------------------------------
52 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
Backing up a VM contains two components - the domain definition, which is an .xml file, and the actual data file, which is usually in qcow2 format. To see where the data files are located we do the following :
virsh domblklist fedora
Target Source
---------------------------------------------------------------
vda /mnt/D0F0D4BFF0D4ACCA/virtual machines/fedora.qcow2
sda -
Now we want to dump the definition file for the Fedora VM to an XML at our backup location:
virsh dumpxml fedora > /location/to/backup/to/fedora.xml
And finally the data file, or hard drive:
cp /mnt/D0F0D4BFF0D4ACCA/virtual machines/fedora.qcow2 /location/to/backup/to
I will show you how to restore these backups in another tutorial coming soon!