Warn if wrong argument order with borgmatic borg #575
Loading…
x
Reference in New Issue
Block a user
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
Steps to reproduce (if a bug)
If you intermix positional arguments with switches, because Borgmatic prepends the repository to
borgmatic borg
, it can result in surprising behavior. Example:Actual behavior (if a bug)
Expected behavior (if a bug)
Show a more useful error message (maybe point to
man borg
). Or automatically fix it for the user (maybe more difficult to do).Other notes / implementation ideas
See
man borg
for details:Environment
borgmatic version: [version here]
1.6.6
borgmatic installation method: RPM package
Borg version: 1.2.2
Python version: 3.10.6
Database version (if applicable):
operating system and version: Fedora 36
Thanks for filing this, and I apologize for the delay in getting to it. I think there are a couple of things going wrong here:
borg
wants flags to come after the repository/archive and path, at least with Borg 1.x. E.g.,borg create repo::test /home/test -s --progress --debug --show-rc
works fine but the borgmatic-generatedborg create 1.2.borg::newtest -s --progress /home/test --debug --show-rc
(with positional arguments and flags interleaved) doesn't. This would be possible to fix, but it'd require more invasive parsing of Borg options so that borgmatic-added options like--debug
could get injected into the right spot. Alternatively, borgmatic could regress the ability to set Borg's verbosity withborgmatic borg
.borg
parameters instead of doing so with borgmatic. From the docs:Besides me unhelpfully saying "just don't do that," it's possible that parsing
borg
arguments could allow borgmatic to helpfully provide an error message that says "just don't do that" whenever a repo or archive is provided directly to borg in aborgmatic borg
command.Some more recent thoughts on this: Looking at the code, I'm beginning to think it's increasingly untenable for borgmatic to try to inject the repository and archive into the right place in the Borg command-line. That's because:
So, instead, here's what I propose. borgmatic could drop the whole repository/archive injection logic. In its place, borgmatic would simply pass a
REPOSITORY
environment variable to Borg so that you could use those values in yourborgmatic borg
command-line. That means it would be the user's responsibility to make use of thatREPOSITORY
in theirborgmatic borg
commands. Example:Or:
(Yes, the single quotes are necessary to prevent the shell borgmatic is running in from trying to resolve the environment variables.)
What about
$ARCHIVE
? Well, since the archive comes from the command-line today (via a borgmatic--archive
flag), it would be a little silly for the user to have to specify an--archive
flag to borgmatic only for borgmatic to turn around and pass that value to Borg via an environment variable. So for archive, I propose to cut out the middleman and require the user to specify it directly as needed for particular Borg sub-commands. And then I'd remove the--archive
flag fromborgmatic borg
. (EDIT: The only problem with this approach is we'd lose support for borgmatic's--archive latest
on theborg
action. Maybe it would be best to leave--archive
and make it plumb through to$ARCHIVE
for optional use in the command?)borgmatic could still continue injecting certain flags like
--debug
and--lock-wait
, because those can unconditionally go at the beginning of the Borg command-line and I think in all cases those will continue to get parsed correctly by Borg. (If not, this part of the plan kind of falls apart.)And yes, all of this would be a breaking change. But given that
borgmatic borg
is hopefully mostly used for one-off commands rather than run in scripts (😬🤞), that might not be too onerous of a change.Well, I went ahead and implemented this in main. See the documentation for the details of what I settled on, which is very similar to the proposal above. I'm still very keen on receiving feedback though—especially before this gets released in the next version of borgmatic! Now you've just got a complete implementation + docs to react to.
From Thomas Waldmann:
This probably means we can lose the whole
'$REPOSITORY'
env var and change it to$BORG_REPO
which Borg will read directly.Implemented. Now commands are even simpler! Documentation update will be published shortly.
Released in borgmatic 1.8.0!