after_backup or on_error hook doesn't work #190
Labels
No Label
bug
data loss
design finalized
good first issue
new feature area
question / support
security
waiting for response
No Milestone
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: borgmatic-collective/borgmatic#190
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
I've got hooks in my config.yaml as follows:
hooks:
before_backup:
- borgmatic -c /borgmatic/config.yaml --list --info | mail -s "[Borg] Starting backup job." me@somewhere.com
after_backup:
- borgmatic -c /borgmatic/config.yaml --list --info | mail -s "[Borg] [SUCCESS] Finished backup job." me@somewhere.com
on_error:
- borgmatic -c /borgmatic/config.yaml --list --info | mail -s "[Borg] [ERROR] Backup job failed." me@somewhere.com
"before_backup" hook works fine, but neither "after_backup" or "on_error" does. No error is produced.
I can see: "/borgmatic/config.yaml: Running command for pre-backup hook" with switched on verbose, and e-mail is send fine.
Then after the backup I get: "/borgmatic/config.yaml: Running command for post-backup hook" and nothing happens... No e-mail sent.
Any suggestions?
Novel ideal.. Using borgmatic to invoke borgmatic! A couple of ideas on debugging this: Try
borgmatic --verbosity 2
to help debug what exactly is going on withafter_backup
oron_error
hooks. That should show you not only the "Running command for post-backup hook" log line, but also (with recent versions of borgmatic) display the exact hook command being executed. It's possible that borgmatic is invoking the hook, but something about the mail is preventing it from sending.. Have you checked your mail log and/or mail queue?Also, what version of borgmatic are you using? You can get that with
borgmatic --version
.Tangentially related: You may be interested in witten/borgmatic#126 because it looks like you're using the hooks to report on overall archive status.
Ok, thanks @witten for an idea. The mystery has been solved.
I run my backups from a docker container. The
after_backup
oron_error
were indeed called, but as they are the final tasks, the container got terminated before the e-mail could be sent. I have added an extra stepsleep 10
to both hooks, and everything works like a charm 😃Glad that did it! One idea, if you want to sidestep the need for a sleep, is to run your email sending from a separate container (or on the host), so that way it can continue the asynchronous task of email sending even after the borgmatic container exits.
Another idea is to run a persistent borgmatic container, e.g. https://hub.docker.com/r/b3vis/borgmatic/