Question: State option on command hooks #1073

Closed
opened 2025-04-15 08:31:49 +00:00 by mrclschstr · 5 comments

Hi Dan,

I'm trying to understand the new "states" option on the command hooks that were added in version 2.0.3. Normally I don't have complicated commands and just use commands that I run before and after backups (create step). What exactly would be the difference in the following two hooks?

- after: action
  when: [create]
  states: [fail]
  run:
    - echo "Something went wrong"
- after: error
  run:
    - echo "Something went wrong"

As I understand it, both are executed in case of an error in the create step, or am I wrong? Are there situations where I should rather use one or the other?

Kind regards,
Marcel

Hi Dan, I'm trying to understand the new "states" option on the command hooks that were added in version 2.0.3. Normally I don't have complicated commands and just use commands that I run before and after backups (create step). What exactly would be the difference in the following two hooks? ```json - after: action when: [create] states: [fail] run: - echo "Something went wrong" ``` ```json - after: error run: - echo "Something went wrong" ``` As I understand it, both are executed in case of an error in the create step, or am I wrong? Are there situations where I should rather use one or the other? Kind regards, Marcel
Owner

You are correct in identifying this as a documentation gap that needs fixing. The basic difference between the two examples you've included is that one runs sooner than the other. The after: action hook runs immediately after the create action fails for a particular repository—so before any subsequent actions for that repository or other repositories even have a chance to run. Whereas the after: error hook doesn't run until all repositories in a configuration file have had a chance to execute.

You are correct in identifying this as a documentation gap that needs fixing. The basic difference between the two examples you've included is that one runs sooner than the other. The `after: action` hook runs immediately after the create action fails for a particular repository—so before any subsequent actions for that repository or other repositories even have a chance to run. Whereas the `after: error` hook doesn't run until all repositories in a configuration file have had a chance to execute.
Author

Thank you for the explanation. So if you only have one repository in the configuration file, it doesn't really make much difference which of the two variants you use. Did I understand that correctly?

Thank you for the explanation. So if you only have one repository in the configuration file, it doesn't really make much difference which of the two variants you use. Did I understand that correctly?
Owner

It doesn't make much difference, but there's still a small difference—if you've got subsequent actions after create for that one repository, after: action with states: [fail] runs before those actions, while after: error runs after them.

It doesn't make much difference, but there's still a small difference—if you've got subsequent actions after `create` for that one repository, `after: action` with `states: [fail]` runs before those actions, while `after: error` runs after them.
Author

Many thanks for the (as always 😄) quick reply and the clarification. The question has been clarified for me and the issue can be closed.

Many thanks for the (as always 😄) quick reply and the clarification. The question has been clarified for me and the issue can be closed.
Owner

Thanks! I'll leave it open for now just as a reminder to clarify this in the docs.

Thanks! I'll leave it open for now just as a reminder to clarify this in the docs.
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#1073
No description provided.