feat: add optional check for existence of source directories

This commit is contained in:
Divyansh Singh 2023-03-18 04:35:55 +05:30
parent a7c055264d
commit d17b2c74db
2 changed files with 24 additions and 0 deletions

View file

@ -306,6 +306,22 @@ def collect_special_file_paths(
) )
def check_all_source_directories_exist(source_directories):
'''
Given a sequence of source directories, check that they all exist. If any do not, raise an
exception.
'''
missing_directories = [
source_directory
for source_directory in source_directories
if not os.path.exists(source_directory)
]
if missing_directories:
raise ValueError(
'Source directories do not exist: {}'.format(', '.join(missing_directories))
)
def create_archive( def create_archive(
dry_run, dry_run,
repository, repository,
@ -331,6 +347,8 @@ def create_archive(
borgmatic_source_directories = expand_directories( borgmatic_source_directories = expand_directories(
collect_borgmatic_source_directories(location_config.get('borgmatic_source_directory')) collect_borgmatic_source_directories(location_config.get('borgmatic_source_directory'))
) )
if location_config.get('source_directories_must_exist', False):
check_all_source_directories_exist(location_config.get('source_directories'))
sources = deduplicate_directories( sources = deduplicate_directories(
map_directories_to_devices( map_directories_to_devices(
expand_directories( expand_directories(

View file

@ -202,6 +202,12 @@ properties:
path prevents "borgmatic restore" from finding any database path prevents "borgmatic restore" from finding any database
dumps created before the change. Defaults to ~/.borgmatic dumps created before the change. Defaults to ~/.borgmatic
example: /tmp/borgmatic example: /tmp/borgmatic
source_directories_must_exist:
type: boolean
description: |
If true, then source directories must exist, otherwise an
error is raised. Defaults to false.
example: true
storage: storage:
type: object type: object
description: | description: |