libvirt - incremental backups for raw devices
Skimming through the latest libvirt releases, to my surprise, i found that latest versions (>= v10.10.0) have added support for the QCOW data-file setting.
Usually the incremental backup feature using bitmaps was limited to qcow2 based images, as there was no way to store the bitmaps persistently within raw devices. This basically ruled out proper incremental backups for direct attached luns, etc.
In the past, there were some discussions how to implement this, mostly by using a separate metadata qcow image, holding the bitmap information persistently.
These approaches have been picked up lately again and have been implemented
In order to be able to use the feature, however, you need to configure the virtual machines and its disks in a special way:
Lets assume you have a virtual machine that uses a raw device
/tmp/datafile.raw
1) Create an qcow image:
# point the data-file to a temporary file, as create will overwrite whatever it finds here
qemu-img create -f qcow2 /tmp/metadata.qcow2 -o data_file=/tmp/TEMPFILE,data_file_raw=true ..
rm -f /tmp/TEMPFILE
2) Now use the amend option to point the qcow image to the right raw device using the data-file option:
qemu-img amend /tmp/metadata.qcow2 -o data_file=/tmp/datafile.raw,data_file_raw=true
3) Reconfigure the virtual machine configuration to look like this:
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2' cache='none' io='native' discard='unmap'/>
<source file='/tmp/metadata.qcow2'>
<dataStore type='file'>
<format type='raw'/>
<source file='/tmp/datafile.raw'/>
</dataStore>
</source>
<target dev='vda' bus='virtio'/>
</disk>
Now its possible to create persistent checkpoints:
virsh checkpoint-create-as vm6 --name test --diskspec vda,bitmap=test
Domain checkpoint test created
and the persistent bitmap will be stored within the metadata image:
qemu-img info /tmp/tmp.16TRBzeeQn/vm6-sda.qcow2
[..]
bitmaps:
[0]:
flags:
[0]: auto
name: test
granularity: 65536
Hoooray.