]> arthur.barton.de Git - backup-script.git/blob - bin/backup-script-wrapper
backup-audit: Exclude quota status files in / directory
[backup-script.git] / bin / backup-script-wrapper
1 #!/bin/bash
2 #
3 # backup-script system for cloning systems using rsync
4 # Copyright (c)2008-2016 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 grep -F "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
25 DELIMITER="- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"
26 HOST=$(hostname -f)
27 LOGFILE="/var/log/$NAME.log"
28 SUBJECT="$NAME results"
29 TMP=$(mktemp /tmp/$NAME.XXXXXXXX) || exit 1
30
31 PATH="$PATH:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
32 export PATH
33
34 exec >"$TMP" 2>&1
35
36 echo "$NAME Report"
37 echo
38 echo " - Host: $(hostname -f)"
39 echo " - User: $(id -un)"
40 echo
41 echo "Command:"
42 echo "$0" "$@"
43 echo
44
45 if echo "$DELIMITER" >>"$LOGFILE" 2>/dev/null; then
46         echo >>"$LOGFILE"
47         "$(dirname "$0")/backup-script" "$@" | tee -a "$LOGFILE"
48         r=${PIPESTATUS[0]}
49 else
50         "$(dirname "$0")/backup-script" "$@"
51         r=$?
52         echo "(Can't write logfile: \"$LOGFILE\"!)"
53 fi
54
55 case "$r" in
56         0)
57                 SUBJECT="$SUBJECT - success"
58                 ;;
59         *)
60                 SUBJECT="$SUBJECT - with ERRORS!"
61 esac
62
63 mail -s "$HOST: $SUBJECT" "$MAILTO" <"$TMP"
64
65 rm -f "$TMP"
66 exit $r
67
68 # -eof-