Commit acd8ba2c authored by thomas.forbriger's avatar thomas.forbriger

BFO2LSDF [TASK]: move to BFO repository

This script is specific to BFO and therefor is moved to
code/dataarchive/csback/production in the BFO repository
parent 0e5ab56e
#!/bin/sh
# This is <BFO2LSDF.sh>
# ----------------------------------------------------------------------------
#
# 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
# 03/07/2014 V1.4 add DL1 data directory
# 07/07/2014 V1.5 - systematically missed rsync exit status
# - re-establish VPN tunnel for each directory
# 15/05/2016 V1.6 add subdirectory for long term archive of
# experiments
# 02/09/2016 V1.7 make program fit for bromo:
# - support dry-run
# - use openvpn instead of vpnc
# 03/09/2016 V1.8 report only IPv4 address
# 12/09/2016 V1.9 do not close VPN connection
#
# ============================================================================
#
# VPN tunnel interface
TUN_INTERFACE=tap0
# approx. 80% of 256 kBit/second
BWLIMIT=20
EXCLUDE="--exclude='.lock'"
DRYRUN=
#DRYRUN=--dry-run
BFO_BASEDIR=/media/BFO_archive
#LSDF_BASEDIR=\
#gpi-lsdf-seis-0001@gpilsdf.gpi.uni-karlsruhe.de:/home/gpi-lsdf-seis-0001/LSDF/SEIS/projects/BFO
LSDF_BASEDIR=\
gpi-lsdf-seis-0001@gpilsdf.gpi.uni-karlsruhe.de:LSDF/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/' 'DL1/' 'SG/UIPC/' 'ExperimentsLTA/')
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
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
# keychain related
source $HOME/.keychain/$HOSTNAME-sh
SSHCMD="/usr/bin/ssh -i $HOME/.ssh/BFOLSDFoper"
# transfer data
for i in ${!DATADIRS[*]}
do
# 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 " | \
head -n 1 | awk '{print $2}')
${LOGGER} -i -p user.info "${LOGINFO} VPN connection already had been \
established using IP ${tunIPs}."
else
# start openvpn (requires appropriate system configuration)
/usr/bin/sudo /usr/sbin/openvpn /etc/openvpn/scc.ovpn.bromo > /dev/null 2>&1
if [ $? -ne 0 ]
then
${LOGGER} -i -p user.err "${LOGERROR} Could not establish VPN \
connection."
exit 2
else
/usr/bin/sleep 10
${IP} addr show ${TUN_INTERFACE} > /dev/null 2>&1
if [ $? -eq 0 ]
then
tunIPs=$(${IP} addr show ${TUN_INTERFACE} | ${GREP} -e "inet " | \
head -n 1 | awk '{print $2}')
${LOGGER} -i -p user.info "${LOGINFO} VPN connection is \
established using IP ${tunIPs}."
else
${LOGGER} -i -p user.err "${LOGERROR} Could not establish VPN \
connection."
exit 2
fi
fi
fi
if test "$DRYRUN" = "--dry-run"
then
${LOGGER} -i -p user.info "${LOGINFO} \
dry-run of copy operation (i.e. files are not actually copied)"
fi
# copy data (compressed)
${LOGGER} -i -p user.info "${LOGINFO}\
${RSYNC} -v -z -a --protocol=29 --bwlimit ${BWLIMIT} ${EXCLUDE} \
-e \"${SSHCMD}\" $DRYRUN \
--backup --suffix=$(date +'%Y%m%d%H%M') \
${EXCLUDE_PATTERNS[$i]} ${BFO_BASEDIR}/${DATADIRS[$i]} \
${LSDF_BASEDIR}/${DATADIRS[$i]}"
set -o pipefail
${RSYNC} -v -z -a --protocol=29 --bwlimit ${BWLIMIT} ${EXCLUDE} \
-e "${SSHCMD}" $DRYRUN \
--backup --suffix=$(date +'%Y%m%d%H%M') \
${EXCLUDE_PATTERNS[$i]} ${BFO_BASEDIR}/${DATADIRS[$i]} \
${LSDF_BASEDIR}/${DATADIRS[$i]} \
|& ${LOGGER} -i -p user.info -t "csback ${LOGINFO}" -s
# write status to logfile
RSYNCSTATUS=$?
if [ $RSYNCSTATUS -eq 0 ]
then
${LOGGER} -i -p user.info "${LOGINFO} Copied data \
'${BFO_BASEDIR}/${DATADIRS[$i]}' \
successfully to LSDF (rsync EXIT CODE: \
${RSYNCSTATUS})."
else
${LOGGER} -i -p user.err "${LOGERROR} While copying data \
'${BFO_BASEDIR}/${DATADIRS[$i]}' to LSDF (rsync EXIT CODE: \
${RSYNCSTATUS})."
fi
done
# ----- END OF BFO2LSDF.sh -----
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment