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

This commit is contained in:
Dan Helfman 2019-12-06 15:58:54 -08:00
parent 2ab9daaa0f
commit df2be9620b
7 changed files with 22 additions and 14 deletions

3
NEWS
View file

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

View file

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

View file

@ -333,7 +333,7 @@ def parse_arguments(*unparsed_arguments):
'--repository', '--repository',
help='Path of repository to use, defaults to the configured repository if there is only one', 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_group.add_argument(
'--mount-point', '--mount-point',
metavar='PATH', metavar='PATH',

View file

@ -252,7 +252,13 @@ def run_actions(
) )
if 'mount' in arguments: if 'mount' in arguments:
if arguments['mount'].repository is None or repository == arguments['mount'].repository: 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( borg_mount.mount_archive(
repository, repository,
arguments['mount'].archive, arguments['mount'].archive,

View file

@ -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 This mounts the entire archive on the given mount point `/mnt`, so that you
can look in there for your files. 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 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. your archive, use the `--path` flag, similar to the `extract` action above.
For instance: For instance:

View file

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

View file

@ -352,13 +352,6 @@ def test_parse_arguments_requires_archive_with_extract():
module.parse_arguments('--config', 'myconfig', '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(): def test_parse_arguments_requires_archive_with_restore():
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default']) flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])