From cf3d7ce6090a251504811d2981c4f76880ed092b Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Tue, 11 Feb 2020 10:53:29 +0100 Subject: [PATCH] create snapshot copy of instance disk on target_vg --- gnt-lv2ssd.sh | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100755 gnt-lv2ssd.sh diff --git a/gnt-lv2ssd.sh b/gnt-lv2ssd.sh new file mode 100755 index 0000000..2c19b4e --- /dev/null +++ b/gnt-lv2ssd.sh @@ -0,0 +1,46 @@ +#!/bin/sh -e + +instance=$1 +disk=$2 +target_vg=ssd + +if [ "$1" = '-' ] ; then + read instance disk +elif [ -z "$instance" -o -z "$disk" ] ; then + echo "Usage: $0 instance disk" + exit 1 +fi + +test -z "$instance" && exit 1 + +instance=`gnt-instance list --no-headers -o name $instance | head -1` + +node=`gnt-instance list -o pnode --no-headers $instance` +echo "# $instance on $node" + +found_lvm=0 + +ssh $node lvs -o name,tags,vg_name,size | grep $instance | tee /dev/shm/$instace.$node.lvs | grep disk${disk}_data | while read lv origin vg size ; do + found_lvm=1 + + disk_nr=`echo $lv | cut -d. -f2 | tr -d a-z_` + echo "# $lv | $origin | $disk_nr" + +cat <<__SHELL__ > /dev/shm/$instance.sh + + lvcreate -L20480m -s -n$lv.snap /dev/$vg/$lv + + lvcreate -L$size -n$instance.$disk_nr $target_vg + + ionice dd if=/dev/$vg/$lv.snap of=/dev/$target_vg/$instance.$disk_nr bs=1M status=progress + + lvremove -f /dev/$vg/$lv.snap + + #rm -v /dev/shm/$instance.sh +__SHELL__ + + scp /dev/shm/$instance.sh $node:/dev/shm/$instance.sh + + ssh $node sh -xe /dev/shm/$instance.sh + +done -- 2.20.1