No way to conditionally list repos #307
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#307
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
I have a repo setup for an offline backup to a drive that's only occasionally connected to my computer. By using a before_backup command like:
I'm able to use borgmatic with or without this device connected and most things work fine. However, whenever I run
borgmatic list
without this drive connected I get an error complaining it couldn't be found.I understand why it wouldn't make sense for my before_backup command to run during
borgmatic list
, but it would be nice to have a similar way for a configured command to be able to check if the drive is connected. In the simplest case there could just be a before_list command.Better still would be some kind of before_use command which runs before any command would look for the repo like check, backup, and list. That way I could put my findmnt command in one place and have all of these commands work as expected.
If something like my before_use idea would be acceptable I can probably find the time to implement it.
Environment
borgmatic version: 1.5.1
Use
sudo borgmatic --version
orsudo pip show borgmatic | grep ^Version
borgmatic installation method: Fedora 31 package
Borg version: borg 1.1.11
Use
sudo borg --version
Python version: Python 3.7.7
Use
python3 --version
operating system and version: Fedora 31 (amd64)
Interesting idea! There's already a
before_everything
hook, but it currently has some limitations:create
action present.So if that last restriction was lifted, and
before_everything
was changed to run for all actions, and it gained soft failure support, do you think that would work for your needs?I think that would work as long as it was also changed to run per-configuration rather than aggregated together (so list would still list all the repos I expect to be available). However, I can imagine all those changes together might break existing workflows so it might be easier to add a new hook instead.
Maybe before_repo? It could even be a hook that exists specifically for this case of checking that the location is ready to be used as I imagine that's somewhat common. Maybe something like repo_condition.
Gotcha. In that case, what do you think of
before_actions
(andafter_actions
), as that would be in keeping with the terminology used elsewhere? It could be used for repo condition checks, or for any other commands the user wants run before all actions (for a particular configuration file).I trust you know what fits much better than I do.
before_actions
andafter_actions
sound good to me. I'll start working on the patch.Awesome!
Ok, it took me way longer than I intended to get to this, but I think I have something that should work.
What I'm wondering now is if there are any relevant tests I can update to include the new hooks. I couldn't find any, but I could try my hand at writing some if you can point me in the right direciton.
Cool! I'm glad to hear you've made progress.
If you've added your calls to the new hooks within
borgmatic/commands/borgmatic.py
in therun_configuration()
function, then the relevant tests would be thetest_run_configuration_*()
tests intests/unit/commands/test_borgmatic.py
.The tests there are kind of obnoxious (lots of mocking), but they do exercise several of the existing hooks.. Look to the names of the test functions. If you run
tox
, you'll get an idea of whether your changes have broken any of the existing tests.Let me know if you need any more help with testing. There's also more here: https://torsion.org/borgmatic/docs/how-to/develop-on-borgmatic/
Closing due to inactivity. Please feel free to reopen if you get back to the pull request. I'm happy to help out with tests!