Backup and Restore a running KVM guest

How to backup and restore a running KVM guest on the command line

If you need to update the software:

yum localinstall ovirt-release36.rpm
yum update -y

Backup the VM:

Assuming a guest called “test”, list location of VM:

virsh domblklist test

Export the XML data that defines the VM:

virsh dumpxml test > test.xml

Take the snapshot:

virsh snapshot-create-as --domain test NAME_OF_SNAPSHOT --diskspec vda,file=/tmp/snapshot_test.qcow2 --disk-only --atomic --no-metadata

Guest is now running in /tmp/snapshot_test.qcow2

Copy XML and original data file to where you need it.

Pivot back to original:

virsh blockcommit test vda --active --verbose --pivot

Restore the VM:

Copy the .qcow2 file into place.

Creating a new vm:

virsh define /path/to/your/xml/test.xml

Check it is present:

virsh list --all

Start the vm:

virsh start test