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 Label
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 New Issue
No description provided.
Delete Branch "%!s(<nil>)"
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/before
With this config, run
borgmatic -v 1
Get error (as expected)
Now change as this:
mv /usr/local/sbin/before /usr/local/sbin/borg-before
Output:
Interesting thing to note is: if I do
exit 2
instead ofexit 1
, the on_error is triggered correctly in both cases, regardles of whether the filename isbefore
orborg-before
Environment
borgmatic version: 1.4.10
Use
sudo borgmatic --version
orsudo pip show borgmatic | grep ^Version
borgmatic installation method: pip
Borg version: 1.1.10
Use
sudo borg --version
Python version: 3.5.3
Use
python3 --version
operating 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_backup
hook, 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!