]> arthur.barton.de Git - backup-script.git/blob - bin/backup-script-wrapper
456f468df17a819314aec23e04f2a8106ed9bcf7
[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 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
25 DELIMITER="- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"
26 HOST=`hostname -f`
27 LOGFILE="/var/log/$NAME.log"
28 PIDFILE="/var/run/$NAME.pid"
29 SUBJECT="$NAME results"
30 TMP=`mktemp /tmp/$NAME.XXXXXXXX` || exit 1
31
32 PATH="$PATH:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
33 export PATH
34
35 # check PID file ("lock file")
36 if [ -e "$PIDFILE" ]; then
37         echo "Lockfile \"$PIDFILE\" already exists."
38         echo "Is an other instance still running?"
39         echo
40         echo -n "Aborted: "; date
41         echo
42         exit 4
43 fi
44
45 exec >"$TMP" 2>&1
46
47 echo "$NAME Report"
48 echo
49 echo " - Host: `hostname -f`"
50 echo " - User: `id -un`"
51 echo
52 echo "Command:"
53 echo "$0" "$@"
54 echo
55
56 if echo "$DELIMITER" >>"$LOGFILE" 2>/dev/null; then
57         echo >>"$LOGFILE"
58         "$(dirname "$0")/backup-script" "$@" | tee -a "$LOGFILE"
59         r=${PIPESTATUS[0]}
60 else
61         "$(dirname "$0")/backup-script" "$@"
62         r=$?
63         echo "(Can't write logfile: \"$LOGFILE\"!)"
64 fi
65
66 case "$r" in
67         0)
68                 ;;
69         *)
70                 SUBJECT="$SUBJECT - with ERRORS!"
71 esac
72
73 cat "$TMP" | mail -s "$HOST: $SUBJECT" "$MAILTO"
74
75 rm -f "$TMP"
76 exit $r
77
78 # -eof-