added one-liner for easy copy/paste
[gnt-info] / rbd-snap-backup.sh
index ed57fd8..2948e3f 100755 (executable)
@@ -1,9 +1,13 @@
 #!/bin/sh -xe
 
+test -z "$1" -o -z "$2" && echo "Usage: $0 instance disk" && exit 1
+
 instance=$1
 disk=$2
+test -z "$backup" && backup="backup"
+test -z "$rsync_host" && rsync_host="lib15"
 
-test -z "$1" -o -z "$2" && echo "Usage: $0 instance disk" && exit 1
+test "`rsync $rsync_host::$backup/$instance/$disk 2>/dev/null | wc -l`" != 1 && echo "ERROR $rsync_host::$backup/$instance/$disk backup target missing" && exit 1
 
 rbd_image=`gnt-instance info --static $instance | grep logical_id: | cut -d\' -f4 | grep "\.rbd\.disk$disk\$"`
 
@@ -16,17 +20,27 @@ rbd clone        $rbd_image@backup backup-$instance-$disk
 
 rbd_dev=`rbd map backup-$instance-$disk`
 
-mkdir /dev/shm/$rbd_image.snap
+test -d /dev/shm/$rbd_image.snap || mkdir /dev/shm/$rbd_image.snap
 
-# FIXME: test does offset work
 # we must mount filesystem read-write to allow journal recovery
-#offset=\`fdisk -l $rbd_dev -u | grep Linux$ | grep $rbd_dev | head -1 | sed 's/\*/ /' | awk '{ print \$2 * 512 }'\`
-#test ! -z "\$offset" && offset=",offset=\$offset"
-#mount $rbd_dev /dev/shm/\$rbd_image.snap -o noatime\$offset
+offset=`fdisk -l $rbd_dev -u -o Device,Start,Type | grep 'Linux$' | grep $rbd_dev | head -1 | sed 's/\*/ /' | awk '{ print \$2 * 512 }'`
+test ! -z "$offset" && offset=",offset=$offset"
 mount $rbd_dev /dev/shm/$rbd_image.snap -o noatime$offset
 
-# execute something on mounted filesystem
-read -p "wait for key" key
+
+# XXX do rsync back to $rsync_host
+
+rsync_args=""
+if rsync $rsync_host::$backup/$instance/rsync.args /dev/shm/$instance-rsync.args 2>/dev/null ; then
+       rsync_args="`cat /dev/shm/$instance-rsync.args`"
+fi
+
+rsync -ravHzXA --inplace --numeric-ids --delete $rsync_args \
+       /dev/shm/$rbd_image.snap/ $rsync_host::$backup/$instance/$disk/ \
+&& ssh -i /root/.ssh/id_dsa-zfs $rsync_host $rsync_host/$backup/$instance/$disk
+
+# XXX backup OK
+
 
 
 umount /dev/shm/$rbd_image.snap