BFO2LSDF.sh 3.72 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/bin/sh
# This is <BFO2LSDF.sh>
# ----------------------------------------------------------------------------
# $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 
Daniel Armbruster's avatar
Daniel Armbruster committed
25
26
#     05/08/2012   V1.0   Daniel Armbruster
#     10/09/2012   V1.1   set bandwidth limit for rsync
27
#     05/02/2013   V1.2   print rsync EXIT CODE to log message
28
29
30
31
32
# 
# ============================================================================
#

TUN_INTERFACE=tun0
Daniel Armbruster's avatar
Daniel Armbruster committed
33
34
# approx. 80% of 256 kBit/second
BWLIMIT=32
35
EXCLUDE="--exclude='.lock'"
36
BFO_BASEDIR=/media/BFO_archive
37
38
39
40
41
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/')
Daniel Armbruster's avatar
Daniel Armbruster committed
42
43
44
45
EXCLUDE_PATTERNS=(\
"--exclude-from=/home/csback/csback.config/BFO2LSDF.sl.exclude" '')
#DATADIRS=('SG/UIPC/')
#EXCLUDE_PATTERNS=('')
46
47
48
49
50
51
52
53
54

# programs
IP=/bin/ip
LOGGER=/bin/logger
NETSTAT=/bin/netstat
JNC=/usr/local/bin/jnc
GREP=/usr/bin/grep
RSYNC=/usr/bin/rsync

55
56
57
# logger
LOGINFO="(BFO2LSDF) INFO:"
LOGERROR="(BFO2LSDF) ERROR:"
58
59

# check for further active processes
60
if pidof -x $(basename $0) > /dev/null
61
then
62
  for p in $(pidof -x $(basename $0)) 
63
64
65
  do
    if [ $p -ne $$ ]
    then
66
67
      ${LOGGER} -i -p user.err "${LOGERROR}  $(basename $0) already running \
with PID $p."
68
69
70
71
72
73
74
75
76
77
78
      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}')
79
80
  ${LOGGER} -i -p user.info "${LOGINFO}  VPN connection already had been \
established using IP ${tunIPs}."
81
82
83
84
85
else
# start juniper network client
  ${JNC} --nox kit > /dev/null 2>&1
  if [ $? -ne 0 ]
  then
86
    ${LOGGER} -i -p user.err "${LOGERROR}  Could not establish VPN \
87
88
89
90
91
connection."
    exit 2
  else
    tunIPs=$(${IP} addr show ${TUN_INTERFACE} | ${GREP} -e "inet" | \
      awk '{print $2}')
92
93
    ${LOGGER} -i -p user.info "${LOGINFO}  VPN connection successfully \
established using IP ${tunIPs}."
94
95
96
97
98
99
100
  fi
fi

# keychain related
source $HOME/.keychain/$HOSTNAME-sh

# transfer data
Daniel Armbruster's avatar
Daniel Armbruster committed
101
for i in ${!DATADIRS[*]}
102
103
do
  # copy data (compressed)
104
  ${RSYNC} -q -z -a --protocol=29 --bwlimit ${BWLIMIT} ${EXCLUDE} \
Daniel Armbruster's avatar
Daniel Armbruster committed
105
106
    ${EXCLUDE_PATTERNS[$i]} ${BFO_BASEDIR}/${DATADIRS[$i]} \
    ${LSDF_BASEDIR}/${DATADIRS[$i]}
107
108
109
110

  # write status to logfile
  if [ $? -eq 0 ]
  then
111
    ${LOGGER} -i -p user.info "${LOGINFO}  Copied data \
112
'${BFO_BASEDIR}/${DATADIRS[$i]}' successfully to LSDF (rsync EXIT CODE: $?)."
113
  else
114
    ${LOGGER} -i -p user.err "${LOGERROR}  While copying data \
115
'${BFO_BASEDIR}/${DATADIRS[$i]}' to LSDF (rsync EXIT CODE: $?)."
116
117
118
119
120
121
122
  fi
done

# close VPN connection
${JNC} stop > /dev/null 2>&1
if [ $? -eq 0 ]
then
123
  ${LOGGER} -i -p user.info "${LOGINFO}  VPN connection successfully closed."
124
else
125
  ${LOGGER} -i -p user.err "${LOGERROR}  While closing VNP connection."
126
127
128
fi

# ----- END OF BFO2LSDF.sh -----