#!/bin/bash # # WizBackup Driver 1.0 # Copyleft 2011 Bernie Innocenti # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, # or (at your option) any later version. if [ $# -lt 1 ] then echo "Usage: $0 [MACHINE-TAB]" echo echo "The MACHINE-TAB file contains hostnames of machines to be backed up, one per line." echo "Empty lines and lines starting with '#' are ignored." exit 1 fi HOSTS=`cat $1 | egrep -v '^#|^ *$'` LOGGROUP=`basename $1` LOGDIR=/var/log/wizbackup LOCKDIR=/var/lock/wizbackup EXCLUDES_DIR=/root/rsync-backups/exclude DEST=/backup today=`date +"%Y%m%d"` mkdir -p $LOGDIR mkdir -p $LOCKDIR if [ "`tty`" = "not a tty" ]; then OUTLOGFILE="$LOGDIR/$LOGGROUP-$today.log" else LOGFILE=/dev/stdout fi for host in $HOSTS; do opts="--exclude-from $EXCLUDES_DIR/ALWAYS" if [ -f "$EXCLUDES_DIR/$host" ]; then opts="$opts --exclude-from $EXCLUDES_DIR/$host" fi start_time=$(date +%s) flock $LOCKDIR/$host wizbackup "$host:/" "$DEST/$host/" $opts >>$LOGFILE 2>&1 result=$? end_time=$(date +%s) report="$(date):$host:$(($end_time-$start_time)):$result" echo $report >>$LOGDIR/$LOGGROUP-report-$today.log [ $result != 0 ] && echo "$report" >>$LOGDIR/$LOGGROUP-fail-$today.log done # TODO: send fail log email report # TODO: delete logs older than 45 days