creativeprojects/resticprofile

[Question] run-after and run-after-fail confusion

xpufx opened this issue ยท 5 comments

xpufx commented

I was initially under the impression that 'run-after-fail' would run when 'restic' errors were encountered, while run-after would run after a successful 'restic' run. As far as I can tell run-after always runs and both are influenced by the outcome of the restic action as well as whatever command/script is being run from run-after. This to me sounds like a bit of a combination of different concerns under one name.

My use case is to push an alert to an endpoint when the restic job fails but also push an alert on success so I can see at a glance that the backup job did run and completed.

How would one accomplish this?

It is right, run-after should only be called if the restic command succeeds, run-after-fail if it fails.
In case you need a command to always run, you have run-finally

There's a graph in the documentation to help visualise the paths on success and error:
https://creativeprojects.github.io/resticprofile/configuration/run_hooks/index.html#order-of-run--during-a-backup

Depending on your endpoint, you can also use the HTTP hooks:
https://creativeprojects.github.io/resticprofile/configuration/http_hooks/index.html

xpufx commented

Great. Something else must be going on in my testing. I will check again and reopen if necessary. Thank you.

By the way. Great project. Thanks for all the work.

xpufx commented

Perhaps I misunderstood but here's what happens in testing.

(The backup job itself completes without an error in all cases. The snippets below are in the backup: section.)

run-after: "echo RUN AFTER !"
run-after-fail: "echo RUN AFTER FAIL!"

This prints "RUN AFTER!".

  run-after: "echo RUN AFTER !; false"
  run-after-fail: "echo RUN AFTER FAIL!"

This prints:

RUN AFTER !
RUN AFTER FAIL!

It does look like the exit status of ERROR in the run-after command is triggering run-after-fail. Actually both the description and the diagram also say this is how it works. I.e "'run-after' from backup section" has an ERROR branch.

Yes, this is by design.

In your case you only send success or failure message to an endpoint so it might not be very intuitive at first.

But run-after can also be called to run a script that is part of the backup. Like un-mounting a disk, restarting a service, copying the backup files to an external location, or other non-idempotent action that should get reviewed on failure.

xpufx commented

Thank you for the explanation.