Live backup of your VM running in KVM under Ubuntu using qcow2 disk images
# First of all disable apparmor to allow access
1 2 3 4 5 |
aa-status aa-complain /usr/sbin/libvirtd aa-complain /etc/apparmor.d/libvirt/libvirt-xxxxxxxxxxxxxxxxxx |
# View disks
1 |
virsh domblklist test-backup |
# Suspend the domain (This is optional. I do this so that the condition of virtual machines remains unchanged during the backup.)
1 |
virsh suspend test-backup |
# Create snapshot
1 2 3 4 5 6 7 |
virsh snapshot-create-as –domain test-backup test-snap1 \ –diskspec vda,file=/home/virtual/test_backup/test-c.img \ –diskspec vdb,file=/home/virtual/test_backup/test-d.img \ –disk-only –atomic |
# or
1 |
virsh snapshot-create-as –domain test-backup test-backup-snap1 –disk-only –atomic |
# View snapshots
1 |
virsh snapshot-list test-backup |
# View disks (it must be running on snapshots)
1 |
virsh domblklist test-backup |
# Copy drives to backup dir
1 2 3 |
rsync -avh –progress drive-c.qcow2 export/drive-c.qcow2-copy rsync -avh –progress drive-d.qcow2 export/drive-d.qcow2-copy |
# Perform active blockcommit by live merging contents
1 2 3 |
virsh blockcommit test-backup vda –active –verbose –pivot virsh blockcommit test-backup vdb –active –verbose –pivot |
# View disks (it must be running on normal drives)
1 |
virsh domblklist test-backup |
# Unsuspend the domain
1 |
virsh resume test-backup |
# View snapshots again
1 |
virsh snapshot-list test-backup |
# Delete snapshots
1 |
virsh snapshot-delete test-backup test-backup-snap1 –metadata |
# View snapshots to check
1 |
virsh snapshot-list test-backup |
# Delete snapshot files
1 2 3 |
rm -f /home/virtual/test_backup/drive-c.test-backup-snap1 rm -f /home/virtual/test_backup/drive-d.test-backup-snap1 |