#!/bin/sh # This is # ---------------------------------------------------------------------------- # $Id$ # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # # Copyright (c) 2012 by Daniel Armbruster (BFO Schiltach) # # Purpose: Backup BFO data to LSDF remotely. # # REVISIONS and CHANGES # 05/08/2012 V1.0 Daniel Armbruster # 10/09/2012 V1.1 set bandwidth limit for rsync # 05/02/2013 V1.2 print rsync EXIT CODE to log message # # ============================================================================ # TUN_INTERFACE=tun0 # approx. 80% of 256 kBit/second BWLIMIT=32 EXCLUDE="--exclude='.lock'" BFO_BASEDIR=/media/BFO_archive LSDF_BASEDIR=\ gpi-seis@gpilsdf.gpi.uni-karlsruhe.de:/gpfs/lsdf/gpi/GPI/SEIS/projects/BFO # NOTE: If adding an additional data directory an exclude pattern must be added, # too. Add an empty string if no data has to be excluded. DATADIRS=('seedlink/' 'SG/UIPC/') EXCLUDE_PATTERNS=(\ "--exclude-from=/home/csback/csback.config/BFO2LSDF.sl.exclude" '') #DATADIRS=('SG/UIPC/') #EXCLUDE_PATTERNS=('') # programs IP=/bin/ip LOGGER=/bin/logger NETSTAT=/bin/netstat JNC=/usr/local/bin/jnc GREP=/usr/bin/grep RSYNC=/usr/bin/rsync # logger LOGINFO="(BFO2LSDF) INFO:" LOGERROR="(BFO2LSDF) ERROR:" # check for further active processes if pidof -x $(basename $0) > /dev/null then for p in $(pidof -x $(basename $0)) do if [ $p -ne $$ ] then ${LOGGER} -i -p user.err "${LOGERROR} $(basename $0) already running \ with PID $p." exit 2 fi done fi # establish VPN connection to KIT ${IP} addr show ${TUN_INTERFACE} > /dev/null 2>&1 if [ $? -eq 0 ] then tunIPs=$(${IP} addr show ${TUN_INTERFACE} | ${GREP} -e "inet" | \ awk '{print $2}') ${LOGGER} -i -p user.info "${LOGINFO} VPN connection already had been \ established using IP ${tunIPs}." else # start juniper network client ${JNC} --nox kit > /dev/null 2>&1 if [ $? -ne 0 ] then ${LOGGER} -i -p user.err "${LOGERROR} Could not establish VPN \ connection." exit 2 else tunIPs=$(${IP} addr show ${TUN_INTERFACE} | ${GREP} -e "inet" | \ awk '{print $2}') ${LOGGER} -i -p user.info "${LOGINFO} VPN connection successfully \ established using IP ${tunIPs}." fi fi # keychain related source $HOME/.keychain/$HOSTNAME-sh # transfer data for i in ${!DATADIRS[*]} do # copy data (compressed) ${RSYNC} -q -z -a --protocol=29 --bwlimit ${BWLIMIT} ${EXCLUDE} \ ${EXCLUDE_PATTERNS[$i]} ${BFO_BASEDIR}/${DATADIRS[$i]} \ ${LSDF_BASEDIR}/${DATADIRS[$i]} # write status to logfile if [ $? -eq 0 ] then ${LOGGER} -i -p user.info "${LOGINFO} Copied data \ '${BFO_BASEDIR}/${DATADIRS[$i]}' successfully to LSDF (rsync EXIT CODE: $?)." else ${LOGGER} -i -p user.err "${LOGERROR} While copying data \ '${BFO_BASEDIR}/${DATADIRS[$i]}' to LSDF (rsync EXIT CODE: $?)." fi done # close VPN connection ${JNC} stop > /dev/null 2>&1 if [ $? -eq 0 ] then ${LOGGER} -i -p user.info "${LOGINFO} VPN connection successfully closed." else ${LOGGER} -i -p user.err "${LOGERROR} While closing VNP connection." fi # ----- END OF BFO2LSDF.sh -----