Shouldn't before_everything
hook also work for list
command?
#463
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
I currently have my backups sitting at a NAS and I connect to them by mounting a SMB mount onto a
/mnt/Backup
directory. That works automatically for backups and restore by usinghooks.before_everything
hook, however for thelist
command it won't work as it won't execute the hook commands beforehand. The same thing goes for theafter_everything
hook.Are there any design reasons why this is not working?
Steps to reproduce (if a bug)
borgmatic list
Actual behavior (if a bug)
You won't see a
Hey!! I ran!
messageExpected behavior (if a bug)
You should probably see it?
Other notes / implementation ideas
Environment
borgmatic version: 1.5.20
borgmatic installation method: Arch Package
Borg version: 1.1.17
Python version: 3.9.7
operating system and version: Arch Linux
Thanks for the ticket! This limitation is by design (and documented as such), but I'd be open to changing the design if it's not working for use cases like this one.
The current idea is that
before_everything
is for any setup needed before running acreate
action to make a backup—run before all other actions across all configuration files. However, as you've discovered, there's often common setup needed for bothcreate
andlist
, like mounting the path where the repository resides.The challenge here is that I believe some folks are using
before_everything
for running commands that they truly only want oncreate
. For instance, in the original ticket wherebefore_everything
was implemented, the use case is for creating a global LVM snapshot before any backups run. Presumably, for that use case, you wouldn't want to create an LVM snapshot before runninglist
.So one option I could see is changing the
before_everything
hook anyway to run on all actions, and those users would just have to somehow deal with the change. Maybe an unnecessary LVM snapshot isn't a big deal, especially if it gets torn down after?Another option would be to add a new hook for your case—something that gets run for any repository setup, regardless of action.
One other more out there idea: If you're just issuing a mount command for the SMB-hosted Borg repository, I could see making a general-purpose borgmatic "mount" hook that lets you specify a path to mount (and mount options) for particular repositories. And then borgmatic would take care of mounting and unmounting it without having to give explicit commands for that. Part of the difficulty there though would be making a clear distinction from the existing
borg mount
andborgmatic mount
actions (which mount archives in repositories, not Unix paths).@witten Thank you for your quick response!
I saw the original ticket and it does make sense to have separate hook configurations for
before-all-backups
andbefore-all-commands
sort of thing.If I understand correctly - and I apologize if I haven't - I think that the chosen naming convention does not reflect the real behavior of the feature (
before_everything
means something wider than something that would be executed prior to the creation of every backup setup). However, I don't like breaking changes that could easily hurt existing users, so I would be very careful about renaming it, and doing it in phases (deprecation then removal). But I also understand that the effort to do that might not worth it.As an alternative, I would suggest a separate feature that could be used as a "pre-command" hook, like that:
And perhaps, if you like, we could even transform the whole hook functionality into a more generic feature so we could have several hooks that would be applied only to specified commands, thus making hooks very flexible. Something like that:
(This is just an idea, not an actual proposal, as it is much more complex :P)
I like the idea because it suggests, by design, a good practice for "linking" a backup repository to the local machine. As you mentioned, however, I don't like the ambiguity that the word
mount
can have in this context, because it can mean something very different on borg. Although borgmatic is a different software, they are very close in the same ecosystem and users could easily get confused about the two operations. Names are indeed hard, but what do you think aboutborgmatic mount-repo
?Your suggestions about the various "before" hooks make sense to me. And, yeah, the challenge is making it flexible enough for the various use cases without making either the user's configuration or the underlying implementation too cumbersome. (Or too different from the existing
before_backup
/before_list
hooks.)As for the mount hook, I wasn't thinking so much of a new borgmatic command-line action, but more of a configuration file hook that automatically gets applied before and after doing anything with a repository. For instance, maybe it could look something like this:
Which would cause borgmatic to mount the repository before use and unmount it afterwards. Of course this would only work if you're using the
mount
command to mount your SMB share andumount
to unmount it...Oh I see! It makes sense, yeah. However I think that this deviates a little bit from the "hook" concept, wouldn't that belong somewhere else in the YAML, such as in the
repository
definition? Maybe something like that:(we can make this backwards compatible)
What do you think?
Yeah, that makes sense in the repository configuration. Good idea! Might take some work to support multiple "types" for the
repositories
schema, but that's hopefully just an implementation detail.I know it's been some time since we discussed, but as I re-read this issue I just wanted to clarify what we've talked and summarize things a little bit.
Is it right to assume that you liked/approved the suggestion of the addition of a new
hooks
entry on the YAML so that we could have multiple entries for commands? I.e.:Amazing, so we're on the same page as far as a new way of defining repositories as described below:
Yes, that makes sense. What do you think of having a starting point so we can build upon later, by adding, for now, only a single adapter named
shellcmd
? That way we wouldn't need to care too much about how to implement the underlying structure of many other adapters at first, and yet we make it very reusable. I.e.:That way we open the possibilities right out the gate and only later we can start thinking about implementing adapters such as
cifs
,nfs
,s3
, etc, and they could be much easily implemented (IMHO).Lastly, if I understand everything correctly, I think the new
repository
declaration suggestion should have a higher priority than thehooks
one, since I believe it is more useful and more semantically accurate for that particular purpose. (In fact it could even deprecates the wholehooks
feature but that might be another topic.)I'd certainly be open to something like this if the use cases support it! Sounds like we might have another solution for your mounting/unmounting use case though. Specifically, your idea about mount/unmount commands on a per-repository basis. I like the princicle of starting small and then expanding from there.
However, I'm now thinking through some of the implications of adding per-repository options as in your example. First of all, there will be the natural feature creep of: Well, why can't I also set the
remote_path
per-repository? E.g., I have a config file with two repositories and I want all the options in common—except forremote_path
. Then, someone else asks: Well what aboutencryption_passhprase
orkeep_hourly
orcheck_last
. Surely those could be snuck in as per-repository options as well. And before you know it, you've gotten a whole borgmatic configuration file stuffed into therepositories:
list—potentially multiple times. (And this isn't all theoretical, either. Folks have already asked for a bunch of this.)Hopefully you'd agree that that could get pretty unwieldy. So I've got an alternate proposal based on some recent enhancements in borgmatic 1.6.0 (just released). Consider something like this:
common.yaml:
repository1.yaml:
repository2.yaml:
This approach is perhaps more verbose or less convenient than what you suggested, but my thinking is that it would support arbitrary borgmatic options per-repository or shared across repositories—including mounting and unmounting.
Thoughts? Please feel free to shoot holes in this proposal.
You're absolutely right. Having experienced people asking for that set of functionality in the past is definitely a tell that maybe the most reusability we could get if we were to redesign the schema, would be to make the config repository-centric rather than backup-centric. But I understand that would be a disrupting change and hardly backwards compatible.
I don't find holes in your suggestion and I really like it -- using YAML's built-in power to work around that is awesome. IMHO though, I find it a little difficult to document that and make it clear that this modular config is meant to make configs more reusable and repository-centric. Maybe this is the case for more advanced users? I know that people using Borg aren't beginners (or are they?), but I'm not a maintainer and I have no idea of your pain in that sense.
The only thing I didn't pick up so far is how that is also going to help with the original issue, which is to be able to reuse
hooks
when runninglist
.It's an interesting idea, and I'd be open to looking at proposals on that front. I think though that while some folks look at their configuration as repository-centric, others look at it by other axes (application-centric, source-centric, etc.). So I'm not sure a one-size-fits-all approach would work here.
I agree with this concern. Borg and borgmatic users, in my experience, include novice users and expert users and everyone in between. I think the best we could do for the YAML include approach would be to document it well and points folks at those docs. Right now, the include functionality is documented. I think what'd be needed on top of that is perhaps a separate how-to guide on using per-repository configuration like the example above, as that's a pretty common use case.
The idea with the proposed
before_repository
andafter_repository
hooks is that they'd run for any borgmatic action related to repositories configured in that configuration file. And that'd includelist
. So yes, you could declare common (or not common!)before
/after
repository hooks and they'd get run for anyborgmatic list
action or any other action, once per repository.Let me know your thoughts!
Yes, I agree that a redesign at this point is overkill, and if not carefully crafted, it might just piss off many users just to benefit a few. The proposal so far is very flexible and meets all requirements you've been asked for, so I wouldn't touch that right now.
Maybe right now that would be the best we could do to address that use-case. The docs are already very good at that (pointing out specific use-cases rather than just being an html version of
--help
), so I suspect this should be fine - at least for now.Got it! It makes sense now and I really like it. TBH, I don't find the naming
*_repository
super intuitive, but I lack the creativity to suggest something else 😂Sounds good!
I appreciate the feedback. (It's much easier to change it at the design stage rather than once implemented and in use.) What do you think of
before_action
/after_action
instead?I took a stab at this in master. The changes will be part of the next release. Here's what's changed:
I didn't deprecate the
before_everything
/after_everything
hooks for now, as I don't yet have a good alterative. But I'd be happy to revisit that on another ticket.Thanks for the discussion and brainstorming!
Just released in borgmatic 1.7.0!
Hi @witten ! Thanks for that! I really appreciate it.
I apologize for not replying the last inquiry, but I'm fine with the chosen naming.
Thanks for being accepting of new ideas and working on them. I'll be changing my configs in the next days and I'll report back my findings (and I'll finally get rid of my wrapper script 😂 )
Awesome! I'm interested to know how it works out.
@witten I just wanted to let you know that everything worked fine! I've updated my settings and so far it's working like a charm!
Thanks for the great work, the docs are also fantastic!
Glad to hear it! Thank you for reporting back.