annotate mpiwg-all-sync.sh @ 0:a8eac765e94d default tip

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