We have two Xen hosting servers that host HVM virtual machines with a mix of operating systems, backed by local LVM volumes. Using ssh and dd here's how we transferred an exact bit copy of an LVM volume from one server to another.
These commands will only work for volumes that are not in use and that are not mounted anywhere. Please don't use these commands on mounted volumes.
On the source server, dcamnode02, lvs shows the current disks available, we wanted to move the svn_root and svn_swap partitions to another server.
root@dcamnode02:~# lvs LV VG Attr LSize Origin Snap% Move Log svn_root vg01 -wi-a- 10.00g svn_swap vg01 -wi-a- 4.00g
First, on the destination server, dcamnode01, we created new lvm volumes of the same size as the ones that we would be transferring.
root@dcamnode01:~# lvcreate -L 10G -n svn_root vg01 Logical volume "svn_root" created root@dcamnode01:~# lvcreate -L 4G -n svn_swap vg01 Logical volume "svn_swap" created
Then on the source server, we used dd to copy the source lvm volumes to newly created lvm volumes on the the destination server.
root@dcamnode02:~# dd if=/dev/vg01/svn_root bs=8M conv=sync,noerror \ | ssh -c blowfish firstname.lastname@example.org "dd of=/dev/vg01/svn_root bs=8M" email@example.com's password: 163840+0 records in 163840+0 records out 10737418240 bytes (11 GB) copied, 199.229 s, 53.9 MB/s 156+345822 records in 156+345822 records out 10737418240 bytes (11 GB) copied, 193.94 s, 55.4 MB/s root@dcamnode02:~#When you use dd and do not specify an output file using 'of=' then the output goes to standard output (the screen). Here we use a pipe to take standard output and pipe it to an ssh command. Ssh then then executes a remote command, 'dd' on the destination server, which is where we give the output file name. The result is that the dd image gets transferred over ssh to the remote server.
After the volume was transferred, an md5sum of the source and destination volumes can be performed to make sure the transfer happened correctly.
root@dcamnode02:~# md5sum /dev/vg01/svn_root 0a310a5aaf3a1b7159c5f68e31525e27 /dev/vg01/svn_root root@dcamnode02:~# root@dcamnode01:~# md5sum /dev/vg01/svn_root 0a310a5aaf3a1b7159c5f68e31525e27 /dev/vg01/svn_root root@dcamnode01:~#Both md5sums match. All is good.