Option to let borgmatic fail if a source_directory is not present #501

Closed
opened 2022-02-21 09:44:52 +00:00 by level420 · 5 comments

What I'm trying to do and why

In some situations it is desireable to let borgmatic create fail with an exit code gt. 0 if a given source_directory entry is not present on the file system.

This is when having a misconfiguration like a typo in the path like /erc vs. /etc.

Other notes / implementation ideas

This could be done either by an additional failonmissingsourcepath or similar command line parameter or an attribute in the borgmatic yaml-File.

Environment

borgmatic version: 1.5.22

borgmatic installation method: pip3 install --upgrade borgmatic

Borg version: 1.1.17

Python version: 3.6.8

operating system and version: AlmaLinux release 8.5 (Arctic Sphynx)

#### What I'm trying to do and why In some situations it is desireable to let `borgmatic create` fail with an exit code gt. 0 if a given `source_directory` entry is not present on the file system. This is when having a misconfiguration like a typo in the path like `/erc` vs. `/etc`. #### Other notes / implementation ideas This could be done either by an additional `failonmissingsourcepath` or similar command line parameter or an attribute in the borgmatic yaml-File. #### Environment **borgmatic version:** 1.5.22 **borgmatic installation method:** pip3 install --upgrade borgmatic **Borg version:** 1.1.17 **Python version:** 3.6.8 **operating system and version:** AlmaLinux release 8.5 (Arctic Sphynx)
Owner

This makes sense to me as a feature. Thanks for filing it! There was a brief period of time when borgmatic did error on missing source directories, but that was an unintentional regression (see #387). I could see having a configuration option as you suggest to optionally turn this behavior back on.

This makes sense to me as a feature. Thanks for filing it! There was a brief period of time when borgmatic did error on missing source directories, but that was an unintentional regression (see #387). I could see having a configuration option as you suggest to optionally turn this behavior back on.
witten added the
good first issue
label 2023-02-04 17:40:03 +00:00
Collaborator

I'd like to work on this, do you want Borgmatic to fail only when a parameter like the mentioned failonmissingsourcepath is provided? I believe it should fail with an exit code > 0 everytime the source_directories entry is not present.

I am thinking of editing the create.py::create_archive() function and adding a for loop to check if all directories exist in the provided source_directories(and throw an error if even one of those does not exist), before this line:

    sources = deduplicate_directories(
        map_directories_to_devices(
            expand_directories(
                tuple(location_config.get('source_directories', ())) + borgmatic_source_directories
            )
        ),
        additional_directory_devices=map_directories_to_devices(
            expand_directories(pattern_root_directories(location_config.get('patterns')))
        ),
    )

Could you help me understand if this would be the correct approach to do this? Thanks!

I'd like to work on this, do you want Borgmatic to fail only when a parameter like the mentioned `failonmissingsourcepath` is provided? I believe it should fail with an exit code > 0 everytime the `source_directories` entry is not present. I am thinking of editing the `create.py::create_archive()` function and adding a for loop to check if all directories exist in the provided `source_directories`(and throw an error if even one of those does not exist), before this line: ```python sources = deduplicate_directories( map_directories_to_devices( expand_directories( tuple(location_config.get('source_directories', ())) + borgmatic_source_directories ) ), additional_directory_devices=map_directories_to_devices( expand_directories(pattern_root_directories(location_config.get('patterns'))) ), ) ``` Could you help me understand if this would be the correct approach to do this? Thanks!
Owner

Given that Borg's default behavior is not to fail on missing directories, I think that should probably continue to be borgmatic's default as well. I can think of use cases where a source directory is only present depending on whether a device or network share is mounted, whether a particular application is running, etc. But I'm open to arguments for the other approach, as well.

If there is an option controlling this behavior, I'd suggest calling it something like source_directories_must_exist in the location section.

I am thinking of editing the create.py::create_archive() function and adding a for loop to check if all directories exist in the provided source_directories(and throw an error if even one of those does not exist), before this line:

Yes, that sounds like the perfect place to do that! It might make sense to put that logic into a separate function though and then call it from there.

Given that Borg's default behavior is *not* to fail on missing directories, I think that should probably continue to be borgmatic's default as well. I can think of use cases where a source directory is only present depending on whether a device or network share is mounted, whether a particular application is running, etc. But I'm open to arguments for the other approach, as well. If there is an option controlling this behavior, I'd suggest calling it something like `source_directories_must_exist` in the `location` section. > I am thinking of editing the create.py::create_archive() function and adding a for loop to check if all directories exist in the provided source_directories(and throw an error if even one of those does not exist), before this line: Yes, that sounds like the perfect place to do that! It might make sense to put that logic into a separate function though and then call it from there.
Owner

Thanks to @diivi, this is now implemented in master as a source_directories_must_exist option and will be part of the next release!

Thanks to @diivi, this is now [implemented](https://github.com/borgmatic-collective/borgmatic/pull/53) in master as a `source_directories_must_exist` option and will be part of the next release!
Owner

Released in borgmatic 1.7.10!

Released in borgmatic 1.7.10!
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#501
No description provided.