head 1.3; access; symbols; locks; strict; comment @# @; 1.3 date 96.10.20.12.51.32; author alexis; state Exp; branches; next 1.2; 1.2 date 96.10.12.09.32.37; author alexis; state Exp; branches; next 1.1; 1.1 date 96.10.05.09.06.29; author alexis; state Exp; branches; next ; desc @ONLINE BACKUP PROGRAM @ 1.3 log @Modified messages slightly. @ text @#!/bin/sh PROGNAME=`basename $0` VERSION=`echo '$Id: olbu,v 1.2 1996/10/12 09:32:37 alexis Exp alexis $' | cut -f3 -d' '` FLAG_FILE=/var/local/lib/$PROGNAME.last OLBU_DIR=/big/olbu DEBUG_LEVEL=2 info() { [ $DEBUG_LEVEL -ge 3 ] && echo "$PROGNAME: INFO: $1" } error() { [ $DEBUG_LEVEL -ge 1 ] && echo "$PROGNAME: ERROR: $1" exit 1 } warning() { [ $DEBUG_LEVEL -ge 2 ] && echo "$PROGNAME: WARNING: $1" } debug() { [ $DEBUG_LEVEL -ge $1 ] && echo "$PROGNAME: DEBUG[$1]: $2" } usage() { echo "Usage: $PROGNAME [ -v | -d level ] " echo " $PROGNAME -V" exit 1 } main() { while [ "X$1" != X ]; do case "$1" in -V) echo "$PROGNAME version $VERSION" exit 0 ;; -v) DEBUG_LEVEL=3 ;; -d) [ "X$2" = X ] && usage DEBUG_LEVEL=$2 shift ;; -*) usage ;; *) break ;; esac shift done [ "X$1" = X ] && usage INTERVAL=$1 [ `id | sed 's/^uid=\([0-9][0-9]*\)(.*/\1/'` -eq 0 ] || error "you must be root to use this program" DAY_THIS_RUN=`date '+%j'` if [ ! -f $FLAG_FILE ]; then # it's not the echo that can't create the output file, but this shell # hence the redirection is outside the brackets and not inside. { echo "-99999" > $FLAG_FILE; } 2>/dev/null [ ! -f $FLAG_FILE ] && error "cannot access $FLAG_FILE" fi [ ! -d $OLBU_DIR ] && error "$OLBU_DIR: no such directory" read DAY_LAST_RUN < $FLAG_FILE expr "$DAY_LAST_RUN" : "^[-]?[0-9][0-9]*$" > /dev/null || error "invalid day number in $FLAG_FILE'" [ $DAY_LAST_RUN -gt $DAY_THIS_RUN ] && DAY_LAST_RUN=`expr $DAY_LAST_RUN - 365` debug 5 "today: $DAY_THIS_RUN, last: $DAY_LAST_RUN, mininterval: $INTERVAL" [ `expr $DAY_THIS_RUN - $DAY_LAST_RUN` -lt $INTERVAL ] && { echo "already run in last $INTERVAL days" exit 0 } echo "backing up in background" ( for DIR in /home/*; do [ ! -f $DIR/.makeolbu ] && { debug 5 "skipping $DIR"; continue; } debug 5 "copying $DIR ..." # tar reports it's stripping leading slashes [ ! -d $OLBU_DIR/`basename $DIR` ] && mkdir $OLBU_DIR/`basename $DIR` nice -n 19 tar cf - $DIR 2>/dev/null | gzip > $OLBU_DIR/`basename $DIR`/olbu.tar.gz chown -R `basename $DIR` $OLBU_DIR/`basename $DIR` done echo "$DAY_THIS_RUN" > $FLAG_FILE ) & } main "$@@" exit 0 @ 1.2 log @fixed messaging functions to take account of debug level. @ text @d3 1 a3 1 VERSION=`echo '$Id: olbu,v 1.1 1996/10/05 09:06:29 alexis Exp alexis $' | cut -f3 -d' '` d74 1 a74 1 info "already run today" d78 1 d84 1 @ 1.1 log @Initial revision @ text @d3 1 a3 1 VERSION=`echo '$Id$' | cut -f3 -d' '` d11 1 a11 1 echo "$PROGNAME: INFO: $1" d16 1 a16 1 echo "$PROGNAME: ERROR: $1" d22 1 a22 1 echo "$PROGNAME: WARNING: $1" d84 1 a84 1 chown `basename $DIR` $OLBU_DIR/`basename $DIR`/olbu.tar.gz @