Skip to content
Paolo Cozzi edited this page Dec 16, 2015 · 5 revisions

Create a snapshot

Check for requirements

Check the type of disk image

Before attempting a snapshot, ensure that the disks you want to backup up are in qcow2 format. You can check this by dumping the domain configuration file with:

$ virsh dumpxml <domain_name>

You can retrieve the list of all defined domains (activer of not) with:

$ virsh list --all

Here you can retrieve a list of the most used virsh commands. By inspecting the XML domain configuration file, you have to search type='qcow2' in the disk block under the devices tag:

  <devices>
    ...
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2' cache='none' discard='unmap'/>
      <source file='/var/lib/libvirt/images/1672ff62-ab9e-49d7-886b-c4ef0e2d2019-0.img'/>
      ...
    </disk>
    ...
  </devices>

Install and configure qemu agent inside Guest

You need to install qemu-guest-agent in order to ensure you have a consistent disk state during snapshot. You can install it via package manager:

# On ubuntu
$ sudo apt-get install qemu-guest-agent
# On centos
$ yum install qemu-guest-agent

Now you can exit from Guest and configure qemu-guest-agent socket. In order to edit Guest XML configuration file:

$ virsh edit <domain_name>

Then place this piece of code under devices section:

  <devices>
    ...
    <channel type="unix">
      <source mode="bind"/>
      <target type="virtio" name="org.qemu.guest_agent.0"/>
    </channel>
    ...
  </devices>

Then restart Guest using virsh:

$ virsh shutdown <domain_name>
$ virsh start <domain_name>

This will create a new virtual serial device within the VM and a new socket under /var/lib/libvirt/qemu/channel/target/. Ensure that Guest agent process is active on Guest. Then test channel on Host, by using

$ virsh qemu-agent-command <domain_name> '{"execute":"guest-info"}' | python -mjson.tool

You can found more information in installing qemu-guest-agent here and here