how to copy a complete logical volume from one server to another.
Situation: I had a server on the east coast with a 100 GB logical volume that I needed to copy to a server on the west coast. Both sites have pretty fast Internet connections. The logical volume I needed to move was the storage volume for a KVM virtual machine.
How I did it:
East coast server: ec01 <-- origin server
West coast server: wc01 <-- destination server
Virtual machine name: vm01
Logical volume name: /dev/mapper/vg_storage-lv_vm01
Basic idea: Create a bzipped image of the logical volume holding the VM image, copy it to the remote server, and load it to a logical volume on the remote server.
I have scratch volumes with lots of space mounted as /scratch on ec01 and wc01. Before starting to copy the VM's storage LV, I first shut down the VM. Once the server was shut down, I could create a consistent image of the LV in my scratch partition. In order to keep the transfer time to the west coast server reasonable and not use any more bandwidth or scratch space than necessary, I bzipped the image as I created it.
Steps:
[root@ec01 ~]# cd /scratch
[root@ec01 scratch]# dd bs=4096k if=/dev/mapper/vg_storage-lv_vm01 | bzip2 -c > lv_vm01.img.bz2 &
Translation: Do a device-to-device copy with a blocksize of 4 MB of the device mapper device for the LV named lv_vm01 on the VG vg_storage. Pipe the output of that to bzip2 to compress it on the fly, and redirect that output into the files called lv_vm01.img.bz2. Background this task so that the shell can continue to be used while its running.
This took a while, because the source LV was about 100 GB. It compressed down to 5.1 GB. While I was waiting for it finish, I ssh'ed to the wc01 server and got it ready:
[root@wc01 ~]# lvcreate -L100G -n lv_vm01 vg_storage
Once the bzipped image of the LV was ready on ec01, I copied it to wc01:
[root@wc01 ~]# cd /scratch
[root@wc01 ~]# rsync --partial --progress -a ec01:/scratch/lv_vm01.img.bz2 .
Translation: Copy the lv_vm01.img.bz2 file from the ec01 server to th wc01 server. Create a temporary file while transferring, so that if the transfer is interrupted, it can be restarted without having to start from the beginning. Show the transfer progress as it runs.
The final step was to load the data from the image file into the LV on wc01:
[root@wc01 ~]# bzcat lv_vm01.img.bz2 | dd of=/dev/mapper/vg_storage-lv_vm01 bs=4096k &
Translation: bunzip the zipped image file on the fly, with output piped to a device-to-device copy of STDIN to the lv_vm01 LV on the vg_storage VG, using a blocksize of 4 MB. Background the tasks so that the terminal can continue to be used while it is running.
Once this was done, I had an exact copy of the LV on the new server, and was able to use it as storage for my copy of the VM on wc01. All I had to do was fire up the VM, log in, and configure a new IP address and routing information for the new box, and everything then worked just fine.
I hope someone finds this helpful.
Situation: I had a server on the east coast with a 100 GB logical volume that I needed to copy to a server on the west coast. Both sites have pretty fast Internet connections. The logical volume I needed to move was the storage volume for a KVM virtual machine.
How I did it:
East coast server: ec01 <-- origin server
West coast server: wc01 <-- destination server
Virtual machine name: vm01
Logical volume name: /dev/mapper/vg_storage-lv_vm01
Basic idea: Create a bzipped image of the logical volume holding the VM image, copy it to the remote server, and load it to a logical volume on the remote server.
I have scratch volumes with lots of space mounted as /scratch on ec01 and wc01. Before starting to copy the VM's storage LV, I first shut down the VM. Once the server was shut down, I could create a consistent image of the LV in my scratch partition. In order to keep the transfer time to the west coast server reasonable and not use any more bandwidth or scratch space than necessary, I bzipped the image as I created it.
Steps:
[root@ec01 ~]# cd /scratch
[root@ec01 scratch]# dd bs=4096k if=/dev/mapper/vg_storage-lv_vm01 | bzip2 -c > lv_vm01.img.bz2 &
Translation: Do a device-to-device copy with a blocksize of 4 MB of the device mapper device for the LV named lv_vm01 on the VG vg_storage. Pipe the output of that to bzip2 to compress it on the fly, and redirect that output into the files called lv_vm01.img.bz2. Background this task so that the shell can continue to be used while its running.
This took a while, because the source LV was about 100 GB. It compressed down to 5.1 GB. While I was waiting for it finish, I ssh'ed to the wc01 server and got it ready:
[root@wc01 ~]# lvcreate -L100G -n lv_vm01 vg_storage
Once the bzipped image of the LV was ready on ec01, I copied it to wc01:
[root@wc01 ~]# cd /scratch
[root@wc01 ~]# rsync --partial --progress -a ec01:/scratch/lv_vm01.img.bz2 .
Translation: Copy the lv_vm01.img.bz2 file from the ec01 server to th wc01 server. Create a temporary file while transferring, so that if the transfer is interrupted, it can be restarted without having to start from the beginning. Show the transfer progress as it runs.
The final step was to load the data from the image file into the LV on wc01:
[root@wc01 ~]# bzcat lv_vm01.img.bz2 | dd of=/dev/mapper/vg_storage-lv_vm01 bs=4096k &
Translation: bunzip the zipped image file on the fly, with output piped to a device-to-device copy of STDIN to the lv_vm01 LV on the vg_storage VG, using a blocksize of 4 MB. Background the tasks so that the terminal can continue to be used while it is running.
Once this was done, I had an exact copy of the LV on the new server, and was able to use it as storage for my copy of the VM on wc01. All I had to do was fire up the VM, log in, and configure a new IP address and routing information for the new box, and everything then worked just fine.
I hope someone finds this helpful.
Source from:James Parks, RHCE
GROUP