#!/bin/bash
-# copyright 2012 Holger Levsen <holger@layer-acht.org>
+# copyright 2012,2013 Holger Levsen <holger@layer-acht.org>
# GPL2 licenced
set -e
#set -x
export
-
#
# Define default settings
#
# dc1+2 (mgmt1)
RSYNC_DST5="liveboot@10.1.1.1/liveboot/"
+ping_and_rsync() {
+ #
+ # only try to rsync if destination is pingable
+ #
+ if ping -c 1 $(echo $1 | sed -s 's#.*@\([0-9.]*\).*#\1#' ) > /dev/null ; then
+ echo "Now rsyncing results to $1 ..."
+ rsync --password-file /etc/rsynclivebuild-send.pass -avv --delete --delete-excluded $RSYNC_FILTER $RSYNC_SRC/ rsync://$1
+ figlet "$2 OK"
+ else
+ echo "Warning: $1 down."
+ echo "Warning: $2 failed."
+ fi
+}
+
#
# check if another rsync is running
#
# Mirror
#
echo
-echo "Now rsyncing results to $RSYNC_DST1 ..."
-rsync --password-file /etc/rsynclivebuild-send.pass -avv --delete --delete-excluded $RSYNC_FILTER $RSYNC_SRC/ rsync://$RSYNC_DST1
-figlet "mirror to r+i OK"
-echo "Now rsyncing results to $RSYNC_DST2 ..."
-rsync --password-file /etc/rsynclivebuild-send.pass -avv --delete --delete-excluded $RSYNC_FILTER $RSYNC_SRC/ rsync://$RSYNC_DST2
-figlet "mirror to storage-dc OK"
-echo "Now rsyncing results to $RSYNC_DST3 ..."
-rsync --password-file /etc/rsynclivebuild-send.pass -avv --delete --delete-excluded $RSYNC_FILTER $RSYNC_SRC/ rsync://$RSYNC_DST3
-figlet "mirror to pbb OK"
-echo "Now rsyncing results to $RSYNC_DST4 ..."
-rsync --password-file /etc/rsynclivebuild-send.pass -avv --delete --delete-excluded $RSYNC_FILTER $RSYNC_SRC/ rsync://$RSYNC_DST4
-figlet "mirror to staging OK"
-echo "Now rsyncing results to $RSYNC_DST5 ..."
-rsync --password-file /etc/rsynclivebuild-send.pass -avv --delete --delete-excluded $RSYNC_FILTER $RSYNC_SRC/ rsync://$RSYNC_DST5
-figlet "mirror to DC1+2 OK"
+ping_and_rsync $RSYNC_DST1 "mirror to r+i"
+ping_and_rsync $RSYNC_DST2 "mirror to storage-dc"
+ping_and_rsync $RSYNC_DST3 "mirror to pbb"
+ping_and_rsync $RSYNC_DST4 "mirror to staging"
+ping_and_rsync $RSYNC_DST5 "mirror to DC1+2"
du -sh /srv/mirror/liveboot
figlet "OK"