after_backup or on_error hook doesn't work #190

Closed
opened 2019-06-15 06:32:41 +00:00 by Plague · 3 comments

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?

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?
Owner

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 with after_backup or on_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.

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 with `after_backup` or `on_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 https://projects.torsion.org/witten/borgmatic/issues/126 because it looks like you're using the hooks to report on overall archive status.
witten added the
question / support
label 2019-06-15 16:23:33 +00:00
Author

Ok, thanks @witten for an idea. The mystery has been solved.
I run my backups from a docker container. The after_backup or on_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 step sleep 10 to both hooks, and everything works like a charm 😃

Ok, thanks @witten for an idea. The mystery has been solved. I run my backups from a docker container. The `after_backup` or `on_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 step `sleep 10` to both hooks, and everything works like a charm :smiley:
Owner

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/

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/
Sign in to join this conversation.
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: borgmatic-collective/borgmatic#190
No description provided.