Annotation of foxridge-archiver/cdli-archive-sync.sh, revision 1.1

1.1     ! casties     1: #!/bin/bash
        !             2: #
        !             3: # script to synchronize the CDLI archive at UCLA to MPIWG
        !             4: #
        !             5: # V0.4.3 (30.6.2006 ROC)
        !             6: 
        !             7: DEBUG=1
        !             8: 
        !             9: LOCKFILE=/var/tmp/cdli-archive-sync.lock
        !            10: LOGFILE=/var/tmp/cdli-archive-sync.log
        !            11: EXCLUDEFILE=/export/home/mirror/scripts/rsync-exclude.list
        !            12: 
        !            13: MAILTO=casties@mpiwg-berlin.mpg.de
        !            14: 
        !            15: MIRDIR=/mpiwg/mirror/CDLI/ARCHIVE
        !            16: REMOTEDIR=/Volumes/cdli_archives
        !            17: 
        !            18: RSYNC=/usr/local/bin/rsync
        !            19: RSYNCHOST="mpiwgsav@backup.cdli.ucla.edu"
        !            20: RSYNCOPTS="--delete --exclude-from=$EXCLUDEFILE"
        !            21: 
        !            22: 
        !            23: function syncdir () {
        !            24: #
        !            25: # sync given directory
        !            26: #
        !            27:     DIR=$1
        !            28:     REMDIR=${2:-$REMOTEDIR}
        !            29:     if [ -n "$3" ] && [ ${3:1:1} == "-" ]
        !            30:     then
        !            31:    # if the third param starts with "-" it's the options
        !            32:    MOREOPTS=$3
        !            33:    shift
        !            34:     fi
        !            35:     LOCDIR=${3:-$MIRDIR}
        !            36:     echo "***** syncing $DIR on $(date)" >> $LOGFILE
        !            37:     if [ -n $DEBUG ] ; then echo "syncing $DIR on $(date)"; fi
        !            38:     if [ -n $DEBUG ] ; then echo "    $RSYNC -ave ssh $RSYNCOPTS $MOREOPTS \"$RSYNCHOST:$REMDIR/$DIR/\" \"$LOCDIR/$DIR/\" >> $LOGFILE 2>&1" >> $LOGFILE ; fi
        !            39:     $RSYNC -ave ssh $RSYNCOPTS $MOREOPTS "$RSYNCHOST:$REMDIR/$DIR/" "$LOCDIR/$DIR/" >> $LOGFILE 2>&1 
        !            40:     if [ $? != 0 ]
        !            41:     then
        !            42:    ERROR="${ERROR}ERROR syncing $DIR "
        !            43:     fi
        !            44: }
        !            45: 
        !            46: 
        !            47: 
        !            48: #
        !            49: # check if script is already running
        !            50: #
        !            51: if [ -f $LOCKFILE ]
        !            52: then
        !            53:     if [ -n $DEBUG ] ; then echo "lockfile present! script seems to be running!"; fi
        !            54: 
        !            55:     mail -t $MAILTO <<EOF
        !            56: Subject: CDLI-ARCHIVE-MIRROR: already running!
        !            57: 
        !            58: `ls -l $LOCKFILE `
        !            59: EOF
        !            60:     exit 1
        !            61: fi
        !            62: 
        !            63: touch $LOCKFILE
        !            64: 
        !            65: echo "***** started `date`" > $LOGFILE
        !            66: 
        !            67: #
        !            68: # sync
        !            69: #
        !            70: syncdir "cdli_archival"
        !            71: 
        !            72: syncdir "cdli_general" "/Volumes/cdli_freeze" "--exclude=englund/personal/"
        !            73: 
        !            74: syncdir "cdli_rawfiles" "/Volumes/cdli_freeze"
        !            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 -c 32-40`
        !            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 <<EOF
        !            91: Subject: $ERROR
        !            92: 
        !            93: $LOG
        !            94: EOF
        !            95: fi
        !            96: 
        !            97: # remove lock
        !            98: 
        !            99: rm $LOCKFILE

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>