Quantcast
Viewing all articles
Browse latest Browse all 171139

Moving non-shared storage VM to another node

Today I needed to move a VM from the local storage on one node, to the local storage on another node with little downtime.
Decided to test a utility called lvmsync. https://github.com/mpalmer/lvmsync

The VM I was moving had two virtual disks stored on lvm volumes.
I first created an identical VM on another node.

Source VM is on nodeA id 130, Destination is on nodeB id 198

After installing lvmsync on both nodes this is what I did:

Created a snapshot on the source for the two VM disks:
Code:

root@nodeA:/ # lvcreate --snapshot -L10G -n vm-130-disk-1-snap /dev/lvmstorage/vm-130-disk-1
root@nodeA:/ # lvcreate --snapshot -L100G -n vm-130-disk-2-snap /dev/lvmstorage/vm-130-disk-2

Next I used dd over SSH to clone the snapshots to the new vm destination.
Code:

root@nodeA:/ # dd if=/dev/lvmstorage/vm-130-disk-1-snap bs=1M | pv -ptrb | ssh root@nodeB dd of=/dev/lvmstorage/vm-198-disk-1 bs=1M
root@nodeA:/ # dd if=/dev/lvmstorage/vm-130-disk-2-snap bs=1M | pv -ptrb | ssh root@nodeB dd of=/dev/lvmstorage/vm-198-disk-2 bs=1M

Now I shutdown the VM, once the source VM is stopped I use lvmsync to copy the changes that were made during the initial copy.
Code:

root@nodeA:/ # lvmsync /dev/lvmstorage/vm-130-disk-1-snap vm6:/dev/lvmstorage/vm-198-disk-1
root@nodeA:/ # lvmsync /dev/lvmstorage/vm-130-disk-2-snap vm6:/dev/lvmstorage/vm-198-disk-2

Those two commands took about 1 minute each.

At this point you can turn the destination VM on since your data is fully cloned.
Since this was the first time ever trying this I decided to get an sha sum of one disk on the source and destination to ensure they are indeed identical.
Code:

root@nodeA:/# sha256sum -b /dev/lvmstorage/vm-130-disk-1
cc5538969acb51bd73759b4c83021cdb35dab37825379659e1b5a760eb741412 */dev/lvmstorage/vm-130-disk-1

root@nodeB:/# sha256sum -b /dev/lvmstorage/vm-198-disk-1
cc5538969acb51bd73759b4c83021cdb35dab37825379659e1b5a760eb741412 */dev/lvmstorage/vm-198-disk-1

Then I started the VM on the destination node, works perfect.


lvmsync also has some other neat features such as being able to store the changes to a file.
I am thinking that maybe with a little scripting it would be easy to setup a process that works like transaction log shipping for databases but for the whole VM.
Imagine tracking all the changes to your VM disks and every 15 minutes shipping the changes to some remote location and auto-applying those changes.

lvmsync is pretty awesome and it works well.
Maybe it will help you solve an issue some day.

Viewing all articles
Browse latest Browse all 171139

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>