Improve docs.
[wizbackup.git] / wizbackup-driver
index 1a5d0bc8bb06f24b0233ba46f7d0219e27a87ceb..957571cb757ed9f3a2857ffd5677b75dcb54bfa7 100755 (executable)
@@ -1,6 +1,6 @@
 #!/bin/bash
 #
 #!/bin/bash
 #
-# WizBackup Driver 1.0
+# WizBackup Driver 1.1
 # Copyright 2011 Bernie Innocenti <bernie@codewiz.org>
 #
 #  This program is free software: you can redistribute it and/or modify
 # Copyright 2011 Bernie Innocenti <bernie@codewiz.org>
 #
 #  This program is free software: you can redistribute it and/or modify
@@ -40,25 +40,34 @@ mkdir -p $LOCKDIR
 
 if [ "`tty`" = "not a tty" ]; then
        LOGFILE="$LOGDIR/$LOGGROUP-$today.log"
 
 if [ "`tty`" = "not a tty" ]; then
        LOGFILE="$LOGDIR/$LOGGROUP-$today.log"
+       FAILLOG="$LOGDIR/$LOGGROUP-fail-$today.log"
+       REPORT="$LOGDIR/$LOGGROUP-report-$today.log"
 else
        LOGFILE=/dev/stdout
 else
        LOGFILE=/dev/stdout
+       FAILLOG=/dev/stderr
+       REPORT=/dev/stdout
 fi
 
 for host in $HOSTS; do
 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)
 
        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 +%s):$host:$(($end_time-$start_time)):$result"
        result=$?
        end_time=$(date +%s)
 
        report="$(date +%s):$host:$(($end_time-$start_time)):$result"
-       echo $report >>$LOGDIR/$LOGGROUP-report-$today.log
-       [ $result != 0 ] && echo "$report" >>$LOGDIR/$LOGGROUP-fail-$today.log
+       echo $report >>"$REPORT"
+       [ $result != 0 ] && echo "$report" >>"$FAILLOG"
 done
 
 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