edoceo

Using LVM Volumes with Linux KVM

How to create a snapshot of a running KVM machine. One process for VM images that are stored on a Logical Volume in LVM, another for QCOW2 image formats.

Backup KVM Virtual Machines on LVM Images

Simple process really, select location to archive to, mount, snapshot existing Logical Volume, archive, done.

A new Logical Volume could be created to store backups, make file-system and mount. Alternatively /mnt/backup could refer to a mounted USB device or network-file-system.

lvcreate --name backup --size 64G vg0
mke2fs -j -L'backup' /dev/vg0/backup
mkdir /mnt/backup
mount /dev/vg0/backup /mnt/backup

Create a snapshot of the partition to backup and mount it.

lvcreate --snapshot --name snap --size 8G /dev/vg0/data
mkdir /mnt/data.snapshot
mount /dev/vg0/snap /mnt/data.snapshot

Now backup the file-system as you normally would, using tar or rsync or similar.

tar -pzc -f /mnt/backup/data-snap.20090912.tgz /mnt/data.snapshot
# or
rsync -a /mnt/data.snapshot/ /mnt/backup/data-snap.20090912/

A bit-wise copy of the logical volume can be created as well, must unmount the file-system before!

umount /mnt/data.snapshot
dd if=/dev/vg0/snap of=/mnt/backup/data-snap.20090912.dd

Backup KVM Virtual Machines on QCOW2 Images

When the images are stored as qcow2 format the backup procedure happens as follows.




See Also