document booting grml cdrom image for recovery
[gnt-info] / gnt-lv-snap-rsync.sh
1 #!/bin/sh -e
2
3 instance=$1
4 disk=$2
5 test -z "$backup" && backup="backup"
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 vg=`gnt-cluster info | grep 'lvm volume group:' | cut -d: -f2 | tr -d ' '`
22
23 ssh $node lvs -o name,tags | grep $instance | tee /dev/shm/$instace.$node.lvs | grep disk${disk}_data | while read lv origin ; do
24         disk_nr=`echo $lv | cut -d. -f2 | tr -d a-z_`
25         echo "# $lv | $origin | $disk_nr"
26
27         rsync_args=""
28         if rsync lib15::$backup/$instance/rsync.args /dev/shm/$instance-rsync.args ; then
29                 rsync_args="`cat /dev/shm/$instance-rsync.args`"
30         fi
31
32 cat <<__SHELL__ > /dev/shm/$instance.sh
33
34         lvcreate -L20480m -s -n$lv.snap /dev/$vg/$lv
35
36         mkdir /dev/shm/$lv.snap
37
38         # we must mount filesystem read-write to allow journal recovery
39         offset=\`fdisk -l /dev/$vg/$lv.snap -u | grep Linux$ | grep /dev/$vg/$lv.snap | head -1 | sed 's/\*/ /' | awk '{ print \$2 * 512 }'\`
40         test ! -z "\$offset" && offset=",offset=\$offset"
41         mount /dev/$vg/$lv.snap /dev/shm/$lv.snap -o noatime\$offset
42
43         rsync -ravHzXA --inplace --numeric-ids --delete $rsync_args /dev/shm/$lv.snap/ lib15::$backup/$instance/$disk_nr/
44
45         umount /dev/shm/$lv.snap
46
47         lvremove -f /dev/$vg/$lv.snap
48
49         rmdir /dev/shm/$lv.snap
50         rm -v /dev/shm/$instance.sh
51 __SHELL__
52
53         scp /dev/shm/$instance.sh $node:/dev/shm/$instance.sh
54
55         ssh $node sh -xe /dev/shm/$instance.sh
56
57         # execute zfs snap on lib15 via ssh command="" wrapper
58         ssh -i /root/.ssh/id_dsa-zfs lib15 lib15/$backup/$instance/$disk_nr
59 done
60
61