Option to let borgmatic fail if a source_directory is not present #501
Loading…
x
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
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
In some situations it is desireable to let
borgmatic create
fail with an exit code gt. 0 if a givensource_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)
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
failonmissingsourcepath
is provided? I believe it should fail with an exit code > 0 everytime thesource_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 providedsource_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
source_directories_must_exist
in thelocation
section.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_exist
option and will be part of the next release!Released in borgmatic 1.7.10!