4 # Copyright 2011 Bernie Innocenti <bernie@codewiz.org>
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License,
9 # or (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 echo "Usage: $0 [MACHINE-TAB] [DEST]"
24 echo "The MACHINE-TAB file contains hostnames of machines to be backed up, one per line."
25 echo "Empty lines and lines starting with '#' are ignored."
29 HOSTS=`cat $1 | egrep -v '^#|^ *$'`
32 LOGGROUP=`basename $1`
33 LOGDIR=/var/log/wizbackup
34 LOCKDIR=/var/lock/wizbackup
35 EXCLUDES_DIR="$DEST/EXCLUDE"
37 today=`date +"%Y%m%d"`
41 if [ "`tty`" = "not a tty" ]; then
42 LOGFILE="$LOGDIR/$LOGGROUP-$today.log"
47 for host in $HOSTS; do
49 for file in "$EXCLUDES_DIR/ALWAYS" "$EXCLUDES_DIR/$host"; do
50 [ -f $file ] && opts="$opts --exclude-from $file"
53 start_time=$(date +%s)
54 flock $LOCKDIR/$host wizbackup "$host:/" "$DEST/$host/" $opts >>$LOGFILE 2>&1
58 report="$(date +%s):$host:$(($end_time-$start_time)):$result"
59 echo $report >>$LOGDIR/$LOGGROUP-report-$today.log
60 [ $result != 0 ] && echo "$report" >>$LOGDIR/$LOGGROUP-fail-$today.log
63 # TODO: send fail log email report
64 # TODO: delete logs older than 45 days