You are here
KVM and Ubuntu Basics – How to Properly Backup your XML Files data networks and data Programming 

KVM and Ubuntu Basics – How to Properly Backup your XML Files

So in finicking around with KVM on my Ubuntu 16.04.1 for a little bit, and i’d like to share something that may really save you a lot of time and effort when it comes to those pesky xml files that describe what your Virtual Machine is, and what it’s got under the hood for resources.

I first came to the realization that there are more than just one XML files generated in order to satsify all the components of the VM.   There’s XML files for

  • Network
  • Network Filter Rules (nfw)
  • Storage
  • The VM itself (defines it’s name/CPU/memory, and also references the above “resource xml files”)
  • other stuff i haven’t yet explored.

Here’s a great link to understanding the contents of the XML file, and which XML files are available:

First of all, you need to understand the lifecycle of a virtual machine from the perspective of the files, most commonly known to be stored in /etc/libvirt/ .

  1. Creation of the XML
  2. Modification of the XML
  3. Destruction of the XML

XML files are either created from hand, either in part or in full, or created automatically based on the the “virt-install” mechanism, which I use to create new virtual machines.

Here’s some examples of virtinst that i’ve used previously:

virt-install --name cacti -r 2000 --disk path=/var/lib/libvirt/images/cacti.img,size=20,sparse=true --network network=private -c /home/account/iso/ubuntu-16.04.1-server-amd64.iso --graphics vnc,listen= --noautoconsole -v

virt-install --name splunk -r 16535 --disk path=/dev/mapper/myhost--vg-splunk,bus=virtio,sparse=false,format=raw --cdrom /home/account/iso/ubuntu-16.04.1-server-amd64.iso --cpu=host --vcpus=4 --graphics vnc,listen= --noautoconsole -v --network network=private

virt-install --name landscape -r 2048 --disk path=/images/landscape.img,size=40,sparse=true,bus=virtio --network network=private -c /home/account/iso/ubuntu-16.04.1-server-amd64.iso --graphics vnc,listen= --noautoconsole -v

virt-install --name tenantinvoice -r 8192 --disk path=/images/tenantinvoice.img,bus=virtio,sparse=true,size=60 --cdrom /home/account/iso/ubuntu-16.04.1-server-amd64.iso --cpu=host --vcpus=4 --network network=private --graphics vnc,listen= --noautoconsole -v

I’ve found that the XML files stored in /etc/libvirt/ , no matter how careful i am with my commands, are absolutely volatile and can be wiped out in a second by a fatal “virsh” command.  Don’t think they’re safe there, even for a second.

One of the best things you can do, when you have a system up and running well, is to copy your entire /etc/libvirt directory to a safe-location.  That way an errant “undefine” command issued in virsh won’t wipe away your existing configs.

  1. Make an executable file somewhere called
    #Purpose = Backup of Important Data
    #Created on 17-1-2012
    #Author = Hafiz Haider
    #Version 1.0
    TIME=`date +%b-%d-%y` # This Command will add date in Backup File Name.
    FILENAME=libvirt-xmls-$TIME.tar.gz # Here i define Backup file name format.
    SRCDIR=/etc/libvirt # Location of Important Data Directory (Source of backup).
    DESDIR=/home/bestpa/backup # Destination of backup file.
  2. Set up a daily cron script to fire it off.
    # m h dom mon dow command
    0 0 * * * /home/bestpa/scripts/




Related posts

Leave a Comment