Browse Source

Mount whole repositories via "borgmatic mount" without any "--archive" flag (#253).

Dan Helfman 5 years ago
parent
commit
df2be9620b

+ 3 - 0
NEWS

@@ -1,3 +1,6 @@
+1.4.18
+ * #253: Mount whole repositories via "borgmatic mount" without any "--archive" flag.
+
 1.4.17
  * #235: Pass extra options directly to particular Borg commands, handy for Borg options that
    borgmatic does not yet support natively. Use "extra_borg_options" in the storage configuration

+ 4 - 4
borgmatic/borg/mount.py

@@ -17,9 +17,9 @@ def mount_archive(
     remote_path=None,
 ):
     '''
-    Given a local or remote repository path, an archive name, a filesystem mount point, zero or more
-    paths to mount from the archive, extra Borg mount options, a storage configuration dict, and
-    optional local and remote Borg paths, mount the archive onto the mount point.
+    Given a local or remote repository path, an optional archive name, a filesystem mount point,
+    zero or more paths to mount from the archive, extra Borg mount options, a storage configuration
+    dict, and optional local and remote Borg paths, mount the archive onto the mount point.
     '''
     umask = storage_config.get('umask', None)
     lock_wait = storage_config.get('lock_wait', None)
@@ -33,7 +33,7 @@ def mount_archive(
         + (('--debug', '--show-rc') if logger.isEnabledFor(logging.DEBUG) else ())
         + (('--foreground',) if foreground else ())
         + (('-o', options) if options else ())
-        + ('::'.join((repository, archive)),)
+        + (('::'.join((repository, archive)),) if archive else (repository,))
         + (mount_point,)
         + (tuple(paths) if paths else ())
     )

+ 1 - 1
borgmatic/commands/arguments.py

@@ -333,7 +333,7 @@ def parse_arguments(*unparsed_arguments):
         '--repository',
         help='Path of repository to use, defaults to the configured repository if there is only one',
     )
-    mount_group.add_argument('--archive', help='Name of archive to mount', required=True)
+    mount_group.add_argument('--archive', help='Name of archive to mount')
     mount_group.add_argument(
         '--mount-point',
         metavar='PATH',

+ 7 - 1
borgmatic/commands/borgmatic.py

@@ -252,7 +252,13 @@ def run_actions(
             )
     if 'mount' in arguments:
         if arguments['mount'].repository is None or repository == arguments['mount'].repository:
-            logger.info('{}: Mounting archive {}'.format(repository, arguments['mount'].archive))
+            if arguments['mount'].archive:
+                logger.info(
+                    '{}: Mounting archive {}'.format(repository, arguments['mount'].archive)
+                )
+            else:
+                logger.info('{}: Mounting repository'.format(repository))
+
             borg_mount.mount_archive(
                 repository,
                 arguments['mount'].archive,

+ 6 - 0
docs/how-to/extract-a-backup.md

@@ -100,6 +100,12 @@ borgmatic mount --archive host-2019-... --mount-point /mnt
 This mounts the entire archive on the given mount point `/mnt`, so that you
 can look in there for your files.
 
+Omit the `--archive` flag to mount all archives (lazy-loaded):
+
+```bash
+borgmatic mount --mount-point /mnt
+```
+
 If you'd like to restrict the mounted filesystem to only particular paths from
 your archive, use the `--path` flag, similar to the `extract` action above.
 For instance:

+ 1 - 1
setup.py

@@ -1,6 +1,6 @@
 from setuptools import find_packages, setup
 
-VERSION = '1.4.17'
+VERSION = '1.4.18'
 
 
 setup(

+ 0 - 7
tests/integration/commands/test_arguments.py

@@ -352,13 +352,6 @@ def test_parse_arguments_requires_archive_with_extract():
         module.parse_arguments('--config', 'myconfig', 'extract')
 
 
-def test_parse_arguments_requires_archive_with_mount():
-    flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
-
-    with pytest.raises(SystemExit):
-        module.parse_arguments('--config', 'myconfig', 'mount', '--mount-point', '/mnt')
-
-
 def test_parse_arguments_requires_archive_with_restore():
     flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])