This bash script copies a logical volume (LVM) from the local machine (source) to a remote server (destination) via SSH, creating before a LVM in the remote machine with the same size as the source volume.
The arguments for the script are:
- group: Volume group
- volume: Logical volume name
- dest: IP address or hostname of the target server and, optionally, SSH user preceded by "@"
- verify (optional): verify the integrity of the transferred data
- Transfer the logical volume under
/dev/vg0/myvol
to the remote server with IP address 192.168.1.2:
./lvm-ssh-transfer.sh --group vg0 --volume myvol --dest root@192.168.1.2
- Transfer a logical volume and also checking the integrity of the transferred data:
./lvm-ssh-transfer.sh --group vg0 --volume myvol --dest root@192.168.1.2 --verify
Just download the file lvm-ssh-transfer.sh
to the source server and execute it. Make sure the .sh file has execution rights.
wget https://raw.githubusercontent.com/daniol/lvm-ssh-transfer/master/lvm-ssh-transfer.sh
chmod +x lvm-ssh-transfer.sh
The following packages are required:
- openssh-client (source server)
- openssh-server (destination server)
- lvm2 (both servers)
If you don't want to enter the SSH password each time, you should copy the ssh public key using ssh-copy-id
. Look here for more information.
The transfer time can take a long time, depending on the size of the volume and the speed of the network. This script does not print any progress and quits when the transfer completes. My tests with a good internet connection in both servers show an average speed around 90 MB/s.
107374182400 bytes (107 GB, 100 GiB) copied, 1194.33 s, 89.9 MB/s
This script must be executed from the source server, as specified.
The script will output error messages and forwards the error code of the commands as exit code.
If you want to get 100% sure if the data was successfully transferred, you can supply the option --verify
to execute sha1sum on the source and target server and verify the integrity of the transferred data.
Just create a new issue or make a pull request if you are developer. You are welcome!
If you only execute dd
and transfer the data via ssh, it is not going to work well as expected, because:
- It will not create the logical volume in the target server
- It would create a file under
/dev/mygroup/myvol
in the root disk - It will not create a local volume using the disk free space
- The copied volume file would not appear on management tools like
lvdisplay
.