On_error hook does not execute when "borg" is part of the command-string in before_backup and exit code is 1 #256
Labels
No labels
blocked
breaking
bug
data loss
design finalized
good first issue
new feature area
question / support
security
waiting for response
No milestone
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
borgmatic-collective/borgmatic#256
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What I'm trying to do and why
Trigger on_error hook when an error occurs.
Steps to reproduce (if a bug)
Run borgmatic with a config file that includes:
Contents of
/usr/local/sbin/beforeWith this config, run
borgmatic -v 1Get error (as expected)
Now change as this:
mv /usr/local/sbin/before /usr/local/sbin/borg-beforeOutput:
Interesting thing to note is: if I do
exit 2instead ofexit 1, the on_error is triggered correctly in both cases, regardles of whether the filename isbeforeorborg-beforeEnvironment
borgmatic version: 1.4.10
Use
sudo borgmatic --versionorsudo pip show borgmatic | grep ^Versionborgmatic installation method: pip
Borg version: 1.1.10
Use
sudo borg --versionPython version: 3.5.3
Use
python3 --versionoperating system and version: Debian 9
This is probably related to: https://projects.torsion.org/witten/borgmatic/src/branch/master/borgmatic/execute.py#L17 ?
Yes, it is due to that line! Here's what's going on: Because Borg considers exit code 2 as an error and exit code 1 as a warning, borgmatic treats any command it runs containing the string "borg" that exits with a value of 1 as just a warning.
And now you've discovered an edge case in which this heuristic doesn't work as intended.. In the
before_backuphook, when you're typically not running Borg itself. Thanks for filing the detailed ticket.. I'll have to think of whether there's a better way to handle this.Thanks for your response!
Would it not be possible to match on the base command name with
^borg$?Or exclude user-defined hooks from the exit code check?
Matching on
^borg$wouldn't work in all cases, because there are hosting providers where the Borg binary includes a version, e.g.borg1. I think your idea of excluding user-defined hooks from the exit code check is probably the way to go.Fixed in borgmatic 1.4.16, just released. Thanks again for reporting this!
Thank you for the fix!