← Back to blog
Backup VM Images without hasslePhoto via Unsplash
LinuxKVMQEMUVirtualization

Backup VM Images without hassle

How to backup VM images in linux. Learn how to backup and restore VM images.

Suyash Singh
Suyash Singh
1 min read

I recently had to temporarily move my VM images out of the machine they run on because of the upgrades the machine needed to go through. I love how seamless & childlike the entire process of backing up and restoration is. Here, I am mostly documenting the process for my own future reference.

The machine I run my VM on went through a complete wipe down, so steps outlined in this post covers the bare minimum details needed for backup restoration. Finer details may vary from scenario to scenario.

Step 1 - Backup/Copy VM images

Find out the location of the VM images

virsh domblklist $VM_NAME

And, then copy the VM images using scp or other means. Also note the permissions you have set for these images using ls -l

Step 2 - Copy the config for VM

Find out the location of the VM images:

virsh dumpxml $VM_NAME > $VM_CONFIG.xml

And, then copy the VM images and config using scp or other means to safer locations.

Step 3 - Restore from backup

When the time comes for restoring the VM backup, simply copy back the images.

scp $VM_IMAGES $DEST_HOST:$PATH_TO_VM_IMAGES
scp $VM_CONFIG.xml $DEST_HOST:$PATH_TO_VM_CONFIG

Initialize VM config from backup config.

virsh define --file $VM_CONFIG.xml

Step 4 - Correct the permissions

Make sure the permissions are similar to what was noted in Step - 1. For instance for default setup conditions it should be <USER>:libvirt for the image files.

Step 5 - Start the vm

virsh start $VM_NAME

That's it. Just like that we can move our vm images around without any problems.