Option to let borgmatic fail if a source_directory is not present
Closedopened 1 year ago by level420 · 4 comments
Reference in New Issue
There is no content yet.
Delete Branch '%!s(<nil>)'
Deleting a branch is permanent. It CANNOT be undone. Continue?
What I'm trying to do and why
In some situations it is desireable to let
borgmatic createfail with an exit code gt. 0 if a given
source_directoryentry is not present on the file system.
This is when having a misconfiguration like a typo in the path like
Other notes / implementation ideas
This could be done either by an additional
failonmissingsourcepathor similar command line parameter or an attribute in the borgmatic yaml-File.
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)
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.
I'd like to work on this, do you want Borgmatic to fail only when a parameter like the mentioned
failonmissingsourcepathis provided? I believe it should fail with an exit code > 0 everytime the
source_directoriesentry 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:
Could you help me understand if this would be the correct approach to do this? Thanks!
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
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.
Thanks to @diivi, this is now implemented in master as a
source_directories_must_existoption and will be part of the next release!