Is it possible to run two borgmatic instances in parallel, both using LVM snapshots? #957

Closed
opened 2024-12-23 09:58:45 +00:00 by aurelg · 5 comments

What I'm trying to do and why

Thanks for all your wonderful work!

I've tested the new lvm snapshot feature, and it's awesome!

I usually run two borgmatic instances at the same time to parallelize backups to two different repositories, each with its own password (one local storage, the other remote).

Steps to reproduce

Run two borgmatic instances in parallel, both using LVM snapshots.

Actual behavior

I noticed the following error in the second borgmatic instance after the first one is completed:

XXXXXXX: Creating archive
/run/media/XXXXX/XXXXXXX: Snapshotting LVM logical volumes
Creating archive at "/run/media/XXXXX/XXXXXXX/XXXXX::XXXXX"
/tmp/borgmatic-7zjcrits/borgmatic/lvm_snapshots/tmp/borgmatic-7zjcrits/borgmatic/bootstrap: stat: [Errno 2] No such file or directory: '/tmp/borgmatic-7zjcrits/borgmatic/lvm_snapshots/tmp/borgmatic-7zjcrits/borgmatic/bootstrap'
XXXXXXX: Pruning archives
XXXXXXX: Compacting segments
compaction freed about 332.18 MB repository space.

Expected behavior

No response

Other notes / implementation ideas

Could the first complete borgmatic instance have removed the snapshots/mounted
tree created by the second one before its completion? This line seems to target all snapshots created by borgmatic, not the one specific of the running instance?

borgmatic version

1.9.4

borgmatic installation method

pipx

Borg version

1.4.0

Python version

3.13.1

Database version (if applicable)

No response

Operating system and version

NAME="Arch Linux" PRETTY_NAME="Arch Linux" ID=arch BUILD_ID=rolling ANSI_COLOR="38;2;23;147;209" HOME_URL="https://archlinux.org/" DOCUMENTATION_URL="https://wiki.archlinux.org/" SUPPORT_URL="https://bbs.archlinux.org/" BUG_REPORT_URL="https://gitlab.archlinux.org/groups/archlinux/-/issues" PRIVACY_POLICY_URL="https://terms.archlinux.org/docs/privacy-policy/" LOGO=archlinux-logo

### What I'm trying to do and why Thanks for all your wonderful work! I've tested the new `lvm` snapshot feature, and it's awesome! I usually run two borgmatic instances at the same time to parallelize backups to two different repositories, each with its own password (one local storage, the other remote). ### Steps to reproduce Run two borgmatic instances in parallel, both using LVM snapshots. ### Actual behavior I noticed the following error in the second borgmatic instance after the first one is completed: ```text XXXXXXX: Creating archive /run/media/XXXXX/XXXXXXX: Snapshotting LVM logical volumes Creating archive at "/run/media/XXXXX/XXXXXXX/XXXXX::XXXXX" /tmp/borgmatic-7zjcrits/borgmatic/lvm_snapshots/tmp/borgmatic-7zjcrits/borgmatic/bootstrap: stat: [Errno 2] No such file or directory: '/tmp/borgmatic-7zjcrits/borgmatic/lvm_snapshots/tmp/borgmatic-7zjcrits/borgmatic/bootstrap' XXXXXXX: Pruning archives XXXXXXX: Compacting segments compaction freed about 332.18 MB repository space. ``` ### Expected behavior _No response_ ### Other notes / implementation ideas Could the first complete borgmatic instance have removed the snapshots/mounted tree created by the second one before its completion? [This line](https://projects.torsion.org/borgmatic-collective/borgmatic/src/commit/ae8a9db27d1f4029df832bcdb675936117514563/borgmatic/hooks/data_source/lvm.py#L368) seems to target all snapshots created by borgmatic, not the one specific of the running instance? ### borgmatic version 1.9.4 ### borgmatic installation method pipx ### Borg version 1.4.0 ### Python version 3.13.1 ### Database version (if applicable) _No response_ ### Operating system and version NAME="Arch Linux" PRETTY_NAME="Arch Linux" ID=arch BUILD_ID=rolling ANSI_COLOR="38;2;23;147;209" HOME_URL="https://archlinux.org/" DOCUMENTATION_URL="https://wiki.archlinux.org/" SUPPORT_URL="https://bbs.archlinux.org/" BUG_REPORT_URL="https://gitlab.archlinux.org/groups/archlinux/-/issues" PRIVACY_POLICY_URL="https://terms.archlinux.org/docs/privacy-policy/" LOGO=archlinux-logo
Owner

I'm glad to hear that the new LVM hook is (mostly) working for you! In terms of running two borgmatic instances in parallel, it's unfortunately not intentionally designed for that currently—not just in the LVM hook but throughout the rest of the application code as well. So in your particular case, yes, one borgmatic instance is removing snapshots created by the other instance. This is actually somewhat intentional; the idea is that there may be snapshots leftover from a prior borgmatic run that errored out, snapshots that we don't want to leave littering the filesystem forever.

A few ideas I can think of for addressing this:

  • borgmatic could make use of the archive_name_format option when removing old snapshots. The idea is that each borgmatic run could use a configuration file with a different archive_name_format, putting that value into each snapshot path. And then that instance of borgmatic could be responsible for cleaning up a different subset of named snapshots.
  • And/or borgmatic could decode the process ID from each snapshot path and only cleanup a snapshot if it's not tied to a currently running borgmatic process.

In any case, there would probably have to be an audit of the whole borgmatic source code as well to make sure that multiple simultaneous processes are really supported. Off the top of my head, I can imagine that things will break or not break depending on the configured or defaulted user runtime directory. Specifically, if borgmatic is using a path in /tmp for the runtime directory, that will conveniently use a differently named path in each borgmatic process. But if using something like /run/user/1234/borgmatic, there could be path collisions between processes.

I'm glad to hear that the new LVM hook is (mostly) working for you! In terms of running two borgmatic instances in parallel, it's unfortunately not intentionally designed for that currently—not just in the LVM hook but throughout the rest of the application code as well. So in your particular case, yes, one borgmatic instance is removing snapshots created by the other instance. This is actually somewhat intentional; the idea is that there may be snapshots leftover from a prior borgmatic run that errored out, snapshots that we don't want to leave littering the filesystem forever. A few ideas I can think of for addressing this: * borgmatic could make use of the `archive_name_format` option when removing old snapshots. The idea is that each borgmatic run could use a configuration file with a different `archive_name_format`, putting that value into each snapshot path. And then that instance of borgmatic could be responsible for cleaning up a different subset of named snapshots. * And/or borgmatic could decode the process ID from each snapshot path and only cleanup a snapshot if it's not tied to a currently running borgmatic process. In any case, there would probably have to be an audit of the whole borgmatic source code as well to make sure that multiple simultaneous processes are really supported. Off the top of my head, I can imagine that things will break or not break depending on the configured or defaulted user runtime directory. Specifically, if borgmatic is using a path in `/tmp` for the runtime directory, that will conveniently use a differently named path in each borgmatic process. But if using something like `/run/user/1234/borgmatic`, there could be path collisions between processes.
Author

Thanks for your kind reply! 🙏 I'll run borgmatic instances sequentially from now on. 👍

Thanks for your kind reply! 🙏 I'll run borgmatic instances sequentially from now on. 👍

I just lost a couple of hours trouble-shooting weird issues where files were not available anymore from Btrfs-snapshots. I had been running multiple Borgmatic processes in parallel because I wanted to speed up the backing up of multiple separate LXC-containers, each with a config file of its own. The background information by @witten explains the behavior perfectly well.
I only wish I had known this before! Do you see a good point to include this in the (excellent!) docu? Maybe on the page How to make per-application backups?

I just lost a couple of hours trouble-shooting weird issues where files were not available anymore from Btrfs-snapshots. I had been running multiple Borgmatic processes in parallel because I wanted to speed up the backing up of multiple separate LXC-containers, each with a config file of its own. The background information by @witten explains the behavior perfectly well. I only wish I had known this before! Do you see a good point to include this in the (excellent!) docu? Maybe on the page [How to make per-application backups](https://torsion.org/borgmatic/how-to/make-per-application-backups/)?
Owner

Sorry to hear you lost a couple hours troubleshooting! Great suggestion.. I've just added a note about this to the per-application backups docs, which should be live shortly.

Sorry to hear you lost a couple hours troubleshooting! Great suggestion.. I've just added a note about this to the per-application backups docs, which should be live shortly.

Thanks a lot for including this and more explanations to the docs!

Thanks a lot for including this and more explanations to the docs!
Sign in to join this conversation.
No milestone
No assignees
3 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#957
No description provided.