Last active
March 5, 2022 05:11
-
-
Save mdpuma/3344d21f6206f7901b697ef767675ecf to your computer and use it in GitHub Desktop.
copy_vm_proxmox_lve.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
SOURCE="vds2" | |
SOURCE_LVM=$1 | |
DEST_LVM=$2 | |
SIZE=$3 | |
if [ "$SIZE" = "" ]; then | |
echo "Please specify size of lvm, example 32G" | |
exit | |
fi | |
IS_OPEN="$(ssh $SOURCE lvdisplay $SOURCE_LVM | grep open | awk '{ print $3}')" | |
if [ $? -ne 0 ]; then | |
echo "Cant find source lvm $SOURCE_LVM on $SOURCE" | |
exit; | |
fi | |
if [ "$IS_OPEN" != 0 ]; then | |
echo "Cant copy lvm $SOURCE_LVM which is in use on $SOURCE" | |
exit | |
fi | |
IS_OPEN="$(lvdisplay $DEST_LVM | grep open | awk '{ print $3 }')" | |
if [ "$IS_OPEN" != "0" ]; then | |
echo "Cant copy lvm $SOURCE_LVM which is in use on $SOURCE" | |
exit | |
fi | |
SIZE1=$(ssh $SOURCE lvdisplay $SOURCE_LVM | grep LV\ Size | awk '{ print $3 }') | |
SIZE2=$(lvdisplay $DEST_LVM | grep LV\ Size | awk '{ print $3 }') | |
if [ "$SIZE1" != "$SIZE2" ]; then | |
echo "Cant copy due to different sizes" | |
exit | |
fi | |
echo "Proceed copying command: ssh $SOURCE dd if=/dev/$SOURCE_LVM bs=16M conv=sparse | pv -s $3 | dd of=/dev/$DEST_LVM bs=16M conv=sparse ? Type y or yes" | |
read int | |
if [ $int = "y" ] || [ $int = "yes" ]; then | |
ssh $SOURCE dd if=/dev/$SOURCE_LVM bs=8M conv=sparse | pv -s $SIZE | dd of=/dev/$DEST_LVM bs=8M conv=sparse | |
fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
DEST="154.56.0.10" | |
SOURCE_LVM=$1 | |
DEST_LVM=$2 | |
SIZE=$3 | |
if [ "$SIZE" = "" ]; then | |
echo "Please specify size of lvm, example 32G" | |
exit | |
fi | |
# check source lvm | |
IS_OPEN="$(lvdisplay $SOURCE_LVM | grep open | awk '{ print $3}')" | |
if [ $? -ne 0 ]; then | |
echo "Cant find source lvm $SOURCE_LVM on source" | |
exit; | |
fi | |
if [ "$IS_OPEN" != 0 ]; then | |
echo "Cant copy lvm $SOURCE_LVM which is in use on source" | |
exit | |
fi | |
# check destination lvm remote | |
IS_OPEN="$(ssh $DEST lvdisplay $DEST_LVM | grep open | awk '{ print $3 }')" | |
if [ "$IS_OPEN" != "0" ]; then | |
echo "Cant copy lvm $DEST_LVM which is in use on $DEST" | |
exit | |
fi | |
# compare sizes | |
SIZE1=$(ssh $DEST lvdisplay $DEST_LVM | grep LV\ Size | awk '{ print $3 }') | |
SIZE2=$(lvdisplay $SOURCE_LVM | grep LV\ Size | awk '{ print $3 }') | |
if [ "$SIZE1" != "$SIZE2" ]; then | |
echo "Cant copy due to different sizes" | |
exit | |
fi | |
echo "Proceed copying command: dd if=/dev/$SOURCE_LVM bs=16M conv=sparse | pv -s $3 | ssh $DEST dd of=/dev/$DEST_LVM bs=16M conv=sparse ? Type y or yes" | |
read int | |
if [ $int = "y" ] || [ $int = "yes" ]; then | |
dd if=/dev/$SOURCE_LVM bs=8M conv=sparse | pv -s $SIZE | ssh $DEST dd of=/dev/$DEST_LVM bs=8M conv=sparse | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment