Backup up VM's and moving them to other servers on qemu-kvm

There's nothing worse than a server with a bunch of VM's on it just stopping to work, and then you not only have to rebuild the server but everything that's on it. I don't have time for rebuilding shit for no good reason, do you?


So back up those VM's using the simple process below. Once they're backed up, you can restore them easily to:

  1. another kvm server sitting on the network

  2. the server that broke, after you rebuild it

  3. some new server that you buy on Ebay for next to nothing (seriously, check out the price of some of the older HP and Dell rack servers)


# virsh dumpxml <virtual server name> >/Storage/backups/<virtualservername>/<virtualservername.xml>

# virsh shutdown <virtual server name>

# cp /var/lib/libvirt/images/<related storage name.qcow2> /Storage/backups/<virtualservername>/<relatedstoragename.qcow2>

# virsh start <virtual server name>


At this point, you sftp them over to the other server so that you have an actual backup.


A real sysadmin would automate this, though I have something different in mind long term so this backup method is just temporary (actually, I need to move a few of these things onto the Dell Poweredge R720 I just put Ubuntu 20.04 on so that I can install Ubuntu over the top of the CentOS 8.1 installation I have on my older server).

Restoring the VM (on this server, or a different one) goes something like this:


Copy the backups onto the server (if they aren't already there). Then just do this:


# virsh define --file /Storage/backups/<virtualservername>/<virtualservername.xml>

# virsh start <virtualservername>


If the virtual machine was already set up on the server and you want to completely blow it away, you may need to do that with the following:



# virsh undefine <virtualservername>

Yeah, I google this and found all of this info on the following page, but my version is condensed has no ads... still, giving credit where it's due.


https://techsoftcenter.com/how-to-kvm-backup-and-restore-in-linux/



5 views0 comments