0
|
1 #!/bin/bash
|
|
2 #
|
|
3 # script to synchronize the MPIWG fileserver
|
|
4 #
|
|
5 # V0.0.3l (7.4.2015 ROC)
|
|
6
|
|
7 DEBUG=1
|
|
8
|
|
9 LOCKFILE=/tmp/mpiwg-all-sync.lock
|
|
10 LOGFILE=/var/tmp/mpiwg-all-sync.log
|
|
11 #EXCLUDEFILE=/usr/local/sbin/rsync-exclude.list
|
|
12
|
|
13 MAILTO=casties@mpiwg-berlin.mpg.de,jsteinhoff@mpiwg-berlin.mpg.de
|
|
14
|
|
15 MIRDIR=
|
|
16 REMOTEDIR=
|
|
17
|
|
18 RSYNC=/usr/bin/rsync
|
|
19 RSYNCHOST="foxridge2"
|
|
20 #RSYNCOPTS="-e rsh --delete --exclude-from=$EXCLUDEFILE"
|
|
21
|
|
22 function syncdir () {
|
|
23 #
|
|
24 # sync given directory
|
|
25 #
|
|
26 DIR=$1
|
|
27 REMDIR=${2:-$REMOTEDIR}
|
|
28 if [ -n "$3" ] && [ ${3:1:1} == "-" ]
|
|
29 then
|
|
30 # if the third param starts with "-" it's the options
|
|
31 MOREOPTS=$3
|
|
32 shift
|
|
33 fi
|
|
34 LOCDIR=${3:-$MIRDIR}
|
|
35 echo "***** syncing $DIR on $(date)" >> $LOGFILE
|
|
36 if [ -n $DEBUG ] ; then echo "syncing $DIR on $(date)"; fi
|
|
37 if [ -n $DEBUG ] ; then echo " $RSYNC ${RSYNCOPTS[@]} $MOREOPTS \"$RSYNCHOST:$REMDIR/$DIR/\" \"$LOCDIR/$DIR/\" >> $LOGFILE 2>&1" >> $LOGFILE ; fi
|
|
38 $RSYNC "${RSYNCOPTS[@]}" $MOREOPTS "$RSYNCHOST:$REMDIR/$DIR/" "$LOCDIR/$DIR/" >> $LOGFILE 2>&1
|
|
39 if [ $? != 0 ]
|
|
40 then
|
|
41 ERROR="${ERROR}ERROR syncing $DIR "
|
|
42 fi
|
|
43 }
|
|
44
|
|
45
|
|
46
|
|
47 #
|
|
48 # check if script is already running
|
|
49 #
|
|
50 if [ -f $LOCKFILE ]
|
|
51 then
|
|
52 if [ -n $DEBUG ] ; then echo "lockfile present! script seems to be running!"; fi
|
|
53
|
|
54 mail -t $MAILTO -s "$( hostname ): MPIWG-ALL-MIRROR: already running!" <<EOF
|
|
55
|
|
56 `ls -l $LOCKFILE `
|
|
57 EOF
|
|
58 exit 1
|
|
59 fi
|
|
60
|
|
61 touch $LOCKFILE
|
|
62
|
|
63 echo "***** started `date`" > $LOGFILE
|
|
64
|
|
65 #
|
|
66 # sync
|
|
67 #
|
|
68
|
|
69 RSYNCOPTS=(-avAX --delete -e 'ssh -i /root/.ssh/foxridge1-sync-mpiwg')
|
|
70 syncdir "mpiwg"
|
|
71
|
|
72 # /usr/local/mpiwg as well
|
|
73 RSYNCOPTS=(-avAX --delete -e 'ssh -i /root/.ssh/foxridge1-sync-usrlocal')
|
|
74 syncdir "mpiwg" "/usr/local" "/usr/local"
|
|
75
|
|
76 #
|
|
77 # send mail with error log if an error occurred
|
|
78 #
|
|
79 if [ -n "$ERROR" ]
|
|
80 then
|
|
81 # don't send logs bigger than 1MB
|
|
82 LOGSIZE=`ls -l $LOGFILE |cut -d' ' -f 5`
|
|
83 if [ "$LOGSIZE" -gt 900000 ]
|
|
84 then
|
|
85 LOG="LOGFILE too big to send: $LOGSIZE"
|
|
86 else
|
|
87 LOG=`cat $LOGFILE`
|
|
88 fi
|
|
89
|
|
90 mail -t $MAILTO -s "foxridge1 mpiwg-all-sync: $ERROR" <<EOF
|
|
91
|
|
92 $LOG
|
|
93 EOF
|
|
94 fi
|
|
95
|
|
96 echo "***** done `date`" >> $LOGFILE
|
|
97
|
|
98 # remove lock
|
|
99 rm $LOCKFILE
|