X-Git-Url: https://codewiz.org/gitweb?p=wizbackup.git;a=blobdiff_plain;f=wizbackup-driver;h=957571cb757ed9f3a2857ffd5677b75dcb54bfa7;hp=10090c90482ce3a5970e41a6c730971dd217e26c;hb=HEAD;hpb=6fa976668baffc519362f6b4e19776491c860670 diff --git a/wizbackup-driver b/wizbackup-driver index 10090c9..957571c 100755 --- a/wizbackup-driver +++ b/wizbackup-driver @@ -1,16 +1,25 @@ #!/bin/bash # -# WizBackup Driver 1.0 -# Copyleft 2011 Bernie Innocenti +# WizBackup Driver 1.1 +# Copyright 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. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . # -# 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 ] +if [ $# -lt 2 ] then - echo "Usage: $0 [MACHINE-TAB]" + echo "Usage: $0 [MACHINE-TAB] [DEST]" 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." @@ -18,38 +27,47 @@ then fi HOSTS=`cat $1 | egrep -v '^#|^ *$'` +DEST="$2" LOGGROUP=`basename $1` LOGDIR=/var/log/wizbackup LOCKDIR=/var/lock/wizbackup -EXCLUDES_DIR=/root/rsync-backups/exclude -DEST=/backup +EXCLUDES_DIR="$DEST/EXCLUDE" today=`date +"%Y%m%d"` mkdir -p $LOGDIR mkdir -p $LOCKDIR if [ "`tty`" = "not a tty" ]; then - OUTLOGFILE="$LOGDIR/$LOGGROUP-$today.log" + LOGFILE="$LOGDIR/$LOGGROUP-$today.log" + FAILLOG="$LOGDIR/$LOGGROUP-fail-$today.log" + REPORT="$LOGDIR/$LOGGROUP-report-$today.log" else LOGFILE=/dev/stdout + FAILLOG=/dev/stderr + REPORT=/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 + opts="" + for file in "$EXCLUDES_DIR/ALWAYS" "$EXCLUDES_DIR/$host"; do + [ -f $file ] && opts="$opts --exclude-from $file" + done start_time=$(date +%s) - flock $LOCKDIR/$host wizbackup "$host:/" "$DEST/$host/" $opts >>$LOGFILE 2>&1 + flock -n $LOCKDIR/$host nice ionice -c2 -n6 \ + 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 + report="$(date +%s):$host:$(($end_time-$start_time)):$result" + echo $report >>"$REPORT" + [ $result != 0 ] && echo "$report" >>"$FAILLOG" done -# TODO: send fail log email report -# TODO: delete logs older than 45 days +if [ -s "$FAILLOG" ]; then + cat "$FAILLOG" + exit 1 +fi + +# TODO: delete logs older than N days