query generated smart files
[gnt-info] / gnt-lv2ssd.sh
1 #!/bin/sh -e
2
3 instance=$1
4 disk=$2
5 target_vg=ssd
6
7 if [ "$1" = '-' ] ; then
8         read instance disk
9 elif [ -z "$instance" -o -z "$disk" ] ; then
10         echo "Usage: $0 instance disk"
11         exit 1
12 fi
13
14 test -z "$instance" && exit 1
15
16 instance=`gnt-instance list --no-headers -o name $instance | head -1`
17
18 node=`gnt-instance list -o pnode --no-headers $instance`
19 echo "# $instance on $node"
20
21 found_lvm=0
22
23 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
24         found_lvm=1
25
26         disk_nr=`echo $lv | cut -d. -f2 | tr -d a-z_`
27         echo "# $lv | $origin | $disk_nr"
28
29 cat <<__SHELL__ > /dev/shm/$instance.sh
30
31         lvcreate -L20480m -s -n$lv.snap /dev/$vg/$lv
32
33         lvcreate -L$size -n$instance.$disk_nr $target_vg
34         
35         ionice dd if=/dev/$vg/$lv.snap of=/dev/$target_vg/$instance.$disk_nr bs=1M status=progress
36
37         lvremove -f /dev/$vg/$lv.snap
38
39         #rm -v /dev/shm/$instance.sh
40 __SHELL__
41
42         scp /dev/shm/$instance.sh $node:/dev/shm/$instance.sh
43
44         ssh $node sh -xe /dev/shm/$instance.sh
45
46
47         echo "TEST: kvm -m 1024 -drive file=/dev/$target_vg/$instance.$disk_nr,format=raw,if=virtio -nographic -net nic -net user"
48         echo "after login: ifdown eth0 ; dhclient eth0"
49 done
50