Hook "on_warning" #606

Closed
opened 2022-10-27 10:59:59 +00:00 by phfn · 8 comments

What I'm trying to do and why

I would like to have a hook (preferebly ntfy) fired, when borg exits with a warning (exit code 1). This would be helpfull, when you try to backup a folder that doas not exist. This could happen when a folder gets moved without your notice.

Other notes / implementation ideas

A config.yaml, after implementing this could look like following:

hooks:
    on_warning:
        - curl -d "Your backups ended with a warning!" ntfy.sh/phfn
        
    ntfy:
        topic: phfn
        
        warn:
            title: Ping!
            message: Your backups ended with a warning!
            
        states:
            - warn

Environment

borgmatic version: [1.7.4]

borgmatic installation method: [pip --user]

Borg version: [1.2.2]

Python version: [3.10.7]

Database version (if applicable): [version here]

operating system and version: [Linux 5.15.74-3-MANJARO]

#### What I'm trying to do and why I would like to have a hook (preferebly ntfy) fired, when borg exits with a warning (exit code 1). This would be helpfull, when you try to backup a folder that doas not exist. This could happen when a folder gets moved without your notice. #### Other notes / implementation ideas A config.yaml, after implementing this could look like following: ```yaml hooks: on_warning: - curl -d "Your backups ended with a warning!" ntfy.sh/phfn ntfy: topic: phfn warn: title: Ping! message: Your backups ended with a warning! states: - warn ``` #### Environment **borgmatic version:** [1.7.4] **borgmatic installation method:** [pip --user] **Borg version:** [1.2.2] **Python version:** [3.10.7] **Database version (if applicable):** [version here] **operating system and version:** [Linux 5.15.74-3-MANJARO]
Owner

To clarify, would either the proposed ntfy-specific warn hook or the on_warning command hook meet your needs? Or do you foresee a need for both? Related tickets: #366, #518, #592.

To clarify, would *either* the proposed ntfy-specific `warn` hook or the `on_warning` command hook meet your needs? Or do you foresee a need for both? Related tickets: #366, #518, #592.
Author

Personally i use ntfy, so i only need the 'warn' hook. But i think an 'on_warning' hook would be usefull in other configurations.

Personally i use ntfy, so i only need the 'warn' hook. But i think an 'on_warning' hook would be usefull in other configurations.
Author

If you agree, that this sounds usefull, i could create a patch.

If you agree, that this sounds usefull, i could create a patch.
Owner

I apologize for the delay here. I would be totally fine with an ntfy "warn" state being supported; I just don't know how easy it would be to add. That's because right now, borgmatic only differentiates between Borg success and failure. A warn state (exit code one, e.g. files missing) is silently treated as a success. So that would have to change in order for the warn state to be available for plumbing through to the ntfy hook.

Having said that, a PR would be welcome if you're still up to it! I'd be happy to answer questions as you go.

I apologize for the delay here. I would be totally fine with an ntfy "warn" state being supported; I just don't know how easy it would be to add. That's because right now, borgmatic only differentiates between Borg success and failure. A warn state (exit code one, e.g. files missing) is silently treated as a success. So that would have to change in order for the warn state to be available for plumbing through to the ntfy hook. Having said that, a PR would be welcome if you're still up to it! I'd be happy to answer questions as you go.
Owner

And here's an alternate idea that may or may not meet your needs: In the next release (1.7.10), there will be a new option in configuration called source_directories_must_exist (implemented in #501), which you can set to true if you'd like borgmatic to check that source directories exist before calling Borg. If they don't exist, borgmatic will error and presumably notify ntfy of the error. (Note that the existence check is not recursive currently.)

And here's an alternate idea that may or may not meet your needs: In the next release (1.7.10), there will be a new option in configuration called `source_directories_must_exist` (implemented in #501), which you can set to `true` if you'd like borgmatic to check that source directories exist before calling Borg. If they don't exist, borgmatic will error and presumably notify ntfy of the error. (Note that the existence check is not recursive currently.)
Author

Nice to here from you. source_directories_must_exist is very cool, but stops, i only want to get warned.

Nice to here from you. `source_directories_must_exist` is very cool, but stops, i only want to get warned.
Owner

Here's an alternate idea: The source_directories_must_exist option effectively triggers a pre-check before Borg even runs; borgmatic probes for each source directory existing and errors if any don't. So if the primary thing you're interested in is whether configured source directories exist, what if borgmatic just issued a warning to ntfy whenever they didn't? It could use the same pre-Borg probing mechanism. That might be easier than checking every call to Borg for warning exit codes. The main downside is that it wouldn't handle other Borg warning states.

Here's an alternate idea: The `source_directories_must_exist` option effectively triggers a pre-check before Borg even runs; borgmatic probes for each source directory existing and errors if any don't. So if the primary thing you're interested in is whether configured source directories exist, what if borgmatic just issued a warning to ntfy whenever they didn't? It could use the same pre-Borg probing mechanism. That might be easier than checking every call to Borg for warning exit codes. The main downside is that it wouldn't handle other Borg warning states.
witten added the
waiting for response
label 2023-06-28 18:41:13 +00:00
witten removed the
waiting for response
label 2023-07-03 16:15:47 +00:00
Owner

Closing for now in favor of source_directories_must_exist. But we can always reopen and revisit this later.

Closing for now in favor of `source_directories_must_exist`. But we can always reopen and revisit this later.
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#606
No description provided.