[Feature] Support Repository lock while running before_backup actions #812

Closed
opened 2024-01-11 08:39:13 +00:00 by marcohald · 2 comments

What I'd like to do and why

It would be great to have the option to lock the Borg Repo before running commands specified in before_backup
Why:

  • Don't start long running / resource intensive before_backup tasks when the repo is locked
  • Other Users cannot mount the Repo by accident while a before_backup task is running and the backup should be successful then

Maybe it is as easy as prepend "borgmatic borg with-lock :: " to each command specific in before_backup but i'm not really sure about it.
And would prefer it to be an option in the borgmatic config file

Other notes / implementation ideas

No response

### What I'd like to do and why It would be great to have the option to lock the Borg Repo before running commands specified in before_backup Why: - Don't start long running / resource intensive before_backup tasks when the repo is locked - Other Users cannot mount the Repo by accident while a before_backup task is running and the backup should be successful then Maybe it is as easy as prepend "borgmatic borg with-lock :: " to each command specific in before_backup but i'm not really sure about it. And would prefer it to be an option in the borgmatic config file ### Other notes / implementation ideas _No response_
Owner

Thanks for taking the time to file this and outline the rationale! Can you give me an example though of some of these before_backup tasks you have in mind so I can better understand your second point—that users should not be able to mount the repo by accident while such a task is running? For instance, for some before_backup tasks I can imagine (like dumping a database or mounting a filesystem), you wouldn't necessarily want to lock the repo because it's not actually being touched by the preparation tasks.

And what do you imagine running at the same time that this lock would protect against? Someone running a borg command manually? Or another instance of borgmatic already running, perhaps started automatically from cron or systemd?

Does the need for the lock encompass any after_backup tasks as well? Or would that be a separate locking need? And what about other action command hooks like before_prune, etc.?

Maybe it is as easy as prepend "borgmatic borg with-lock :: " to each command specific in before_backup but i'm not really sure about it.
And would prefer it to be an option in the borgmatic config file

If you mean that a user would manually prepend that to each command, I generally don't recommend invoking borgmatic from borgmatic, as that opens up the possibility of recursion problems. But if you meant that borgmatic would implicitly prepend each before_backup command with borg with-lock ..., that might work. The big downside I could see though is that the lock would unlock between each command (and between the final command and the actual borg create), thereby creating an opportunity for another process to slip in and steal the lock and do something unexpected.

Depending on the use case, it might make more sense to take out a lock (maybe even a borgmatic-specific lock) before all before_backup commands and then unlock it after they're all done or even maybe after borg create completes.

Thanks for taking the time to file this and outline the rationale! Can you give me an example though of some of these `before_backup` tasks you have in mind so I can better understand your second point—that users should not be able to mount the repo by accident while such a task is running? For instance, for some `before_backup` tasks I can imagine (like dumping a database or mounting a filesystem), you *wouldn't* necessarily want to lock the repo because it's not actually being touched by the preparation tasks. And what do you imagine running at the same time that this lock would protect against? Someone running a `borg` command manually? Or another instance of `borgmatic` already running, perhaps started automatically from cron or systemd? Does the need for the lock encompass any `after_backup` tasks as well? Or would that be a separate locking need? And what about other action command hooks like `before_prune`, etc.? > Maybe it is as easy as prepend "borgmatic borg with-lock :: " to each command specific in before_backup but i'm not really sure about it. And would prefer it to be an option in the borgmatic config file If you mean that a user would manually prepend that to each command, I generally don't recommend invoking borgmatic from borgmatic, as that opens up the possibility of recursion problems. But if you meant that borgmatic would implicitly prepend each `before_backup` command with `borg with-lock ...`, that might work. The big downside I could see though is that the lock would unlock between each command (and between the final command and the actual `borg create`), thereby creating an opportunity for another process to slip in and steal the lock and do something unexpected. Depending on the use case, it might make more sense to take out a lock (maybe even a borgmatic-specific lock) before all `before_backup` commands and then unlock it after they're all done or even maybe after `borg create` completes.
witten added the
waiting for response
label 2024-02-06 18:05:43 +00:00
Owner

Closing this for now due to inactivity, but I'd be happy to revisit this if you'd like to discuss further! Thanks.

Closing this for now due to inactivity, but I'd be happy to revisit this if you'd like to discuss further! Thanks.
witten removed the
waiting for response
label 2024-03-12 04:16:09 +00:00
Sign in to join this conversation.
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: borgmatic-collective/borgmatic#812
No description provided.