Skip to content

Instantly share code, notes, and snippets.

@chrislovecnm
Created June 12, 2014 19:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrislovecnm/369aa4adc381e129ea92 to your computer and use it in GitHub Desktop.
Save chrislovecnm/369aa4adc381e129ea92 to your computer and use it in GitHub Desktop.
Copy a LVS logical volume between volume groups
#!/bin/bash
export mount_point=$1
if [[ -z "$mount_point" ]]; then
echo "pass in drive name as first argument";
exit 1;
fi
# Sanity check that lv is not used
lvuses="$( lvdisplay -c /dev/vg0/${mount_point} | cut -d ':' -f 6 )"
if [ $lvuses -gt 0 ]; then
echo "lv $mount_point is in use"
exit 1 ;
fi
#obtain lv size (in sectors)
export lvsize="$( lvdisplay -c /dev/vg0/${mount_point} | cut -d ':' -f 7 )"
echo "lvsize ${lvsize}"
#create destination
lvcreate -L "${lvsize}s" vg1 -n ${mount_point} || exit 1
echo "lvcreated /dev/vg1/${mount_point}"
# copy
echo "starting copy
time dd if=/dev/vg0/${mount_point} of=/dev/vg1/${mount_point}
echo "DONE!!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment