on_error hook needs corresponding on_success hook #475

Closed
opened 2021-12-06 13:32:28 +00:00 by DonRichie · 5 comments

Problem

I am currently using an selfhosted instance of healthchecks.io to monitor my backups.
The "everything" check fails, but is displayed as succeeded.

Why it is happening

You can see a picture like this for the check receiving pre_everything, post_everything and failure hooks.

oh

The following is happening:

  1. The pre_everything hook correctly signals the start of the borgmatic execution.
  2. After that a failure happens and the fail hook is called (borg lock taken in this case).
  3. But now immediately after it the post_everything hook is called signaling a success.

The result is that the failed backup is marked as success. This is a completely expected behaviour since the post_everything hook is supposted to be called in any case. But it doesn't fit to my use case.

Proposed solution

Please add an on_success hook corresponding to the on_error hook to enable users to correctly distinguish between succeeded and failed backups.

### Problem I am currently using an selfhosted instance of healthchecks.io to monitor my backups. The "everything" check fails, but is displayed as succeeded. ### Why it is happening You can see a picture like this for the check receiving pre_everything, post_everything and failure hooks. ![oh](https://s.ricl.de/fail_leads_to_success.png) **The following is happening:** 1. The pre_everything hook correctly signals the start of the borgmatic execution. 2. After that a failure happens and the fail hook is called (borg lock taken in this case). 3. But now immediately after it the post_everything hook is called signaling a success. The result is that the failed backup is marked as success. This is a completely expected behaviour since the post_everything hook is supposted to be called in any case. But it doesn't fit to my use case. ### Proposed solution Please add an on_success hook corresponding to the on_error hook to enable users to correctly distinguish between succeeded and failed backups.
Owner

Thanks for bringing this to my attention. Two thoughts:

  1. The existing after_backup hook is basically the "success" hook for create actions. It's triggered when the backup has completed successfully. However...
  2. Is a reason you're not able to use the built-in borgmatic Healthchecks hook to talk to your self-hosted Healthchecks server instead of the pre_everything and post_everything hooks? The built-in Healthchecks integration should handle all of your use cases for transmitting successes and failures. And if it's not, it should probably be fixed!
Thanks for bringing this to my attention. Two thoughts: 1. The existing `after_backup` hook is basically the "success" hook for `create` actions. It's triggered when the backup has completed successfully. However... 2. Is a reason you're not able to use the [built-in borgmatic Healthchecks hook](https://torsion.org/borgmatic/docs/how-to/monitor-your-backups/#healthchecks-hook) to talk to your self-hosted Healthchecks server instead of the `pre_everything` and `post_everything` hooks? The built-in Healthchecks integration *should* handle all of your use cases for transmitting successes and failures. And if it's not, it should probably be fixed!
Author

My specific use case is that I wanted to find out how much time the subtastsks backup, check and create take.
Therefore I created 4 separate healthchecks and linked them to before_, after_, pre_everything and post_everything. The on_error hook is sent to the everything check.

Using the healthchecks integration should only give me the total time of the whole borgmatic run as I understood it.

By the way my favourite solution would be having a hook for statistics. Sending some measured durations as json string via http POST. That would require templating for the http-body, but enable me to send my statistics directly to influxdb for example.

My specific use case is that I wanted to find out how much time the subtastsks backup, check and create take. Therefore I created 4 separate healthchecks and linked them to before_*, after_*, pre_everything and post_everything. The on_error hook is sent to the everything check. Using the healthchecks integration should only give me the total time of the whole borgmatic run as I understood it. By the way my favourite solution would be having a hook for statistics. Sending some measured durations as json string via http POST. That would require templating for the http-body, but enable me to send my statistics directly to influxdb for example.

What about covering this with #473?

What about covering this with #473?
Owner

I apologize for the delay in getting back to this. I think I'm missing something though. "backup" and "create" are really the same thing as far as borgmatic is concerned. For that, you should be able to use the before_backup/after_backup hooks. And for check, the before_check/after_check hooks should work. Similar thing if you want to time any of the other actions. That means you might not need to use the everything hooks?

I agree that a statistic hook would be pretty cool.

I apologize for the delay in getting back to this. I think I'm missing something though. "backup" and "create" are really the same thing as far as borgmatic is concerned. For that, you should be able to use the `before_backup`/`after_backup` hooks. And for check, the `before_check`/`after_check` hooks should work. Similar thing if you want to time any of the other actions. That means you might not need to use the everything hooks? I agree that a statistic hook would be pretty cool.
witten added the
waiting for response
label 2022-05-24 21:29:58 +00:00
Owner

Closing this for now, but feel free to follow up. We can always reopen it. Thanks!

Closing this for now, but feel free to follow up. We can always reopen it. Thanks!
witten removed the
waiting for response
label 2022-10-05 06:13:02 +00:00
Sign in to join this conversation.
No Milestone
No Assignees
3 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#475
No description provided.