Skip to content

Concepts

  • Snapshots take the disk, memory, and device state of a domain at a point-of-time, and save it for future use.
  • Checkpoints serve as a point in time to identify which portions of a guest's disks have changed after that time, making it possible to perform incremental and differential backups. It serves to copy only the difference, not the hole data. Useful for external programs to do differential backups.
  • Push Backup: libvirt creates a backup in an external location.
  • Pull Backup: libvirt exposes the data that needs to be written out and allows a third-party tool to copy them out reliably. Uses NBD to connect and can connect to other servers over TCP.
  • quiescing: pause the VM. If you do a backup while the VM is writing to disk, some data may be lost.

Backups

If backupxml is omitted, this defaults to a full backup using a push model to filenames generated by libvirt; supplying XML allows fine-tuning such as requesting an incremental backup relative to an earlier checkpoint, controlling which disks participate or which filenames are involved, or requesting the use of a pull model backup. The backup-dumpxml command shows any resulting values assigned by libvirt. For more information on backup XML, see: https://libvirt.org/formatbackup.html

Simple full backup

It backs up all the drives and appends the date in format 1642352802

Create a backup.

virsh backup-begin vm-name

Check the status of the backup operation.

virsh domjobinfo vm-name
virsh domjobinfo vm-name --completed

Convert the date.

date --date='@1642352802'
date --date='@1642352802' --uct

Custom full backup

In order to change the output name or exclude drives it is needed an XML. All the options can be found in https://libvirt.org/formatbackup.html or /usr/share/libvirt/schemas/domainbackup.rng

backup.xml
---
<domainbackup mode='push'>
    <disks>
        <disk name='vda' backup='yes' type='file'>
            <target file='/path/to/file/file.raw'/>
            <driver type='raw'/>
        </disk>
        <disk name='vdb' backup='no' type='file'/>
    </disks>
</domainbackup>

And pass the file to the backup

virsh backup-begin vm-name backup.xml
virsh backup-begin vm-name --backupxml backup.xml

Incremental backup

The output file needs to exist...

Create a XML file to define the backup job.

backup.xml
---
<domainbackup mode='push'>
    <disks>
        <disk name='vda' backup='yes' type='file'>
            <target file='/path/to/file/file.backup.qcow2'/>
            <driver type='qcow2'/>
        </disk>
    </disks>
</domainbackup>

Run the backup with the option --reuse-external

virsh backup-begin vm-name backup.xml --reuse-external

Note: due to the way qcow2 images work, the deleted data inside the original image takes space in the backup. The image can be "cleaned" with qemu-img:

qemu-img convert -O qcow2 origin.qcow2 destination.qcow2

And even compress

qemu-img convert -c -O qcow2 origin.qcow2 destination.qcow2

Commands

autostart

sudo virsh autostart name
sudo virsh autostart name --disable

Links to sources