I want a robust method of taking backup of KVM VPS of qcow2 file, while running. After searching for a long time I found that we can use rsync for live backup. I used following command for rsync:
rsync -avh /vms/base.qcow2 /backup/backup.qcow2
It worked properly. But I am afraid it may corrupt backup qcow2 image if backup is taken while VPS is being changed due to write and delete operations (Like installing new software or update).
Therefore taking backup from snapshot of live VPS seems more interesting option.
I used following commands for taking backup of running VPS:
qemu-img create -f qcow2 -b base.qcow2 snapshot.qcow2
2.Convert snapshot in raw image format (.img) :
qemu-img convert -O raw snapshot.qcow2 /backup/backup.img
To restore VPS :
3.Convert raw image in qcow2 image:
qemu-img convert -O qcow2 /backup/backup.img base.qcow2
Then we can start VPS by
virsh create base.xml command.
Even though this method also work perfectly I am still not sure if this is proper method to take backup of running VPS. I found nice documentation on qemu-img commands here and here. But they didn't mention anything about converting snapshot of live VPS in raw image.
Which method is more suitable for live VPS backup? Is converting snapshot in raw image safe?
If I could get nice detailed documentation on how snapshot and base files behave in certain conditions that will be very helpful.
Maybe we can also convert base qcow2 image into raw backup file instead of converting snapshot.
So command flow will be :
1. Create snapshot
2. Convert base qcow2 into backup raw image
3. Commit snapshot changes into base image
4. Delete snapshot
I tried this and it worked fine on small VPS of 5GB. But is there any possibility of error or VPS corruption when VPS size is huge?
Thanks in advance...