# HG changeset patch # User casties # Date 1227103121 -3600 # Node ID 86965c7658a90c1dda510fb4e49974dc5da79250 # Parent b762b5af6e42f44879307fc97de27053896fb077 *** empty log message *** diff -r b762b5af6e42 -r 86965c7658a9 cdli-archive-sync.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cdli-archive-sync.sh Wed Nov 19 14:58:41 2008 +0100 @@ -0,0 +1,99 @@ +#!/bin/bash +# +# script to synchronize the CDLI archive at UCLA to MPIWG +# +# V0.4.3 (30.6.2006 ROC) + +DEBUG=1 + +LOCKFILE=/var/tmp/cdli-archive-sync.lock +LOGFILE=/var/tmp/cdli-archive-sync.log +EXCLUDEFILE=/export/home/mirror/scripts/rsync-exclude.list + +MAILTO=casties@mpiwg-berlin.mpg.de + +MIRDIR=/mpiwg/mirror/CDLI/ARCHIVE +REMOTEDIR=/Volumes/cdli_archives + +RSYNC=/usr/local/bin/rsync +RSYNCHOST="mpiwgsav@backup.cdli.ucla.edu" +RSYNCOPTS="--delete --exclude-from=$EXCLUDEFILE" + + +function syncdir () { +# +# sync given directory +# + DIR=$1 + REMDIR=${2:-$REMOTEDIR} + if [ -n "$3" ] && [ ${3:1:1} == "-" ] + then + # if the third param starts with "-" it's the options + MOREOPTS=$3 + shift + fi + LOCDIR=${3:-$MIRDIR} + echo "***** syncing $DIR on $(date)" >> $LOGFILE + if [ -n $DEBUG ] ; then echo "syncing $DIR on $(date)"; fi + if [ -n $DEBUG ] ; then echo " $RSYNC -ave ssh $RSYNCOPTS $MOREOPTS \"$RSYNCHOST:$REMDIR/$DIR/\" \"$LOCDIR/$DIR/\" >> $LOGFILE 2>&1" >> $LOGFILE ; fi + $RSYNC -ave ssh $RSYNCOPTS $MOREOPTS "$RSYNCHOST:$REMDIR/$DIR/" "$LOCDIR/$DIR/" >> $LOGFILE 2>&1 + if [ $? != 0 ] + then + ERROR="${ERROR}ERROR syncing $DIR " + fi +} + + + +# +# check if script is already running +# +if [ -f $LOCKFILE ] +then + if [ -n $DEBUG ] ; then echo "lockfile present! script seems to be running!"; fi + + mail -t $MAILTO < $LOGFILE + +# +# sync +# +syncdir "cdli_archival" + +syncdir "cdli_general" "/Volumes/cdli_freeze" "--exclude=englund/personal/" + +syncdir "cdli_rawfiles" "/Volumes/cdli_freeze" + +# +# send mail with error log if an error occurred +# +if [ -n "$ERROR" ] +then + # don't send logs bigger than 1MB + LOGSIZE=`ls -l $LOGFILE |cut -c 32-40` + if [ "$LOGSIZE" -gt 900000 ] + then + LOG="LOGFILE too big to send: $LOGSIZE" + else + LOG=`cat $LOGFILE` + fi + + mail -t $MAILTO <