1

I'm using KVM to live migrate VMs from one host to another. I have already written a web ui to do that. Now I want to implement a progress bar.

My idea is to compare the file size of the disk on the source and on the target while it's migrating.

Server1:

ls -ls /data/file.raw
858963 -rw------- 1 root root 21474836480 Dec 15 13:39 file.raw

Server2:

ls -ls /data/file.raw
698543 -rw------- 1 root root 21474836480 Dec 15 13:39 file.raw

Now, I took the allocated value and calculated it in percent.

100 / 858963 * 698543 = 81%

Fine. but there is one problem:

The disk is not sparse. The total size of the file is 1717926 blocks. Actually, there are only 858963 blocks allocated. So the live migration is still copying the empty parts of the file while my progress bar is already at 100%

I already tried around with du and stat.

How to get only the transferred file size of the disk?

  • The file, not the disk, is sparse. Try du -h /data/file.raw (real disk use) and du -h --apparent-size /data/file.raw. What do you use (with all args) to transfer the file? – Giacomo Catenazzi Dec 19 '16 at 15:42
  • I'm using libvirt to migrate the VM. virsh migrate --verbose --live --copy-storage-all $VM_NAME qemu+ssh://$TARGET/system According to the docs, it is using rsync. du -h returns 858M and du -h --apparent-size returns 6.0G – Vince Dec 20 '16 at 7:03
0

Use virsh migrate as already suggested, or take advantage of rsync's sparse files support, from man rsync:

-S, --sparse Try to handle sparse files efficiently so they take up less space on the destination.

Try rsync -ahHS, add -P if you want to see progress and speed

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.