-
Notifications
You must be signed in to change notification settings - Fork 15
TKLBAM - email notification on failed backup #757
Copy link
Copy link
Open
Labels
Milestone
Description
A long term TurnKey/TKLBAM user asked
Is there a way through TKLBAM, or possible even Duplicity, to have the system send an email if there was an error during the backup process?
I forwarded the question to @lirazsiri (the TKLBAM Daddy), here's his response:
- There is currently no support for this within TKLBAM or Duplicity but you could do this by wrapping around tklbam-backup, so it emails the output log if it errors out. Something like this::
TMPOUT=$(mktemp)
(tklbam-backup 2>&1) > $TMPOUT && cat $TMPOUT || \
(cat $TMPOUT | mail -s "tklbam-backup error" user@example.com)
rm $TMPOUT
If you don't want the whole backup log you could use tail instead of cat.
- The place to add support for this inside TKLBAM would be as a hook that runs when you have an exception. Right now the backup hook has the following states:
- pre
- inspect
- post
If we added 'error' then you could write a hook that sends an e-mail when the backup errors out. The backup code is already inside a try clause so you'd just have to modify the exception handler to launch.
If he doesn't like the shell solution, here's an untested patch::
diff --git a/cmd_backup.py b/cmd_backup.py
index 0b5fa36..d11702a 100755
--- a/cmd_backup.py
+++ b/cmd_backup.py
@@ -476,6 +476,8 @@ def main():
print >> log_fh
traceback.print_exc(file=log_fh)
+ hooks.backup.error()
+
raise
finally:
diff --git a/hooks.py b/hooks.py
index 22eb9a2..5f85ed8 100644
--- a/hooks.py
+++ b/hooks.py
@@ -80,6 +80,9 @@ class Hooks:
def post(self):
self._run("post")
+ def error(self):
+ self._run("error")
+
def inspect(self, extras_path):
orig_cwd = os.getcwd()
Reactions are currently unavailable