]> arthur.barton.de Git - backup-script.git/blob - bin/backup-script-wrapper
backup-status: Correctly show "current" snapshot as newest
[backup-script.git] / bin / backup-script-wrapper
1 #!/bin/bash
2 #
3 # backup-script system for cloning systems using rsync
4 # Copyright (c)2008-2015 Alexander Barton, alex@barton.de
5 #
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 2 of the License, or
9 # (at your option) any later version.
10 # Please read the file COPYING, README and AUTHORS for more information.
11 #
12
13 if [ -z "$MAILTO" ]; then
14         if id "logcheck" >/dev/null 2>&1; then
15                 MAILTO="logcheck"
16         elif fgrep "logcheck:" /etc/aliases >/dev/null 2>&1; then
17                 MAILTO="logcheck"
18         else
19                 MAILTO="root"
20         fi
21 fi
22
23 NAME="backup-script"
24 HOST=`hostname -f`
25 TMP=`mktemp /tmp/$NAME.XXXXXXXX` || exit 1
26 LOGFILE="/var/log/backup-script.log"
27 DELIMITER="- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"
28 SUBJECT="$NAME results"
29
30 PATH="$PATH:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
31 export PATH
32
33 exec >"$TMP" 2>&1
34
35 echo "$NAME Report"
36 echo
37 echo " - Host: `hostname -f`"
38 echo " - User: `id -un`"
39 echo
40
41 if echo "$DELIMITER" >>"$LOGFILE" 2>/dev/null; then
42         echo >>"$LOGFILE"
43         "$(dirname "$0")/backup-script" "$@" | tee -a "$LOGFILE"
44         r=${PIPESTATUS[0]}
45 else
46         "$(dirname "$0")/backup-script" "$@"
47         r=$?
48         echo "(Can't write logfile: \"$LOGFILE\"!)"
49 fi
50
51 case "$r" in
52         0)
53                 ;;
54         *)
55                 SUBJECT="$SUBJECT - with ERRORS!"
56 esac
57
58 cat "$TMP" | mail -s "$HOST: $SUBJECT" "$MAILTO"
59
60 rm -f "$TMP"
61 exit $r
62
63 # -eof-