2
0
Эх сурвалжийг харах

feat: add optional check for existence of source directories

Divyansh Singh 2 жил өмнө
parent
commit
d17b2c74db

+ 18 - 0
borgmatic/borg/create.py

@@ -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(
     dry_run,
     repository,
@@ -331,6 +347,8 @@ def create_archive(
     borgmatic_source_directories = expand_directories(
         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(
         map_directories_to_devices(
             expand_directories(

+ 6 - 0
borgmatic/config/schema.yaml

@@ -202,6 +202,12 @@ properties:
                     path prevents "borgmatic restore" from finding any database
                     dumps created before the change. Defaults to ~/.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:
         type: object
         description: |