Extract files to a particular directory via "borgmatic extract --destination" flag. Also rename "--restore-path" to "--path" to reduce confusion.

This commit is contained in:
Dan Helfman 2019-11-01 10:00:26 -07:00
parent 589fc30fc8
commit e3dd545345
8 changed files with 47 additions and 22 deletions

5
NEWS
View file

@ -1,3 +1,8 @@
1.4.2
* Extract files to a particular directory via "borgmatic extract --destination" flag.
* Rename "borgmatic extract --restore-path" flag to "--path" to reduce confusion with the separate
"borgmatic restore" action. Any uses of "--restore-path" will continue working.
1.4.1 1.4.1
* #229: Restore backed up PostgreSQL databases via "borgmatic restore" action. See the * #229: Restore backed up PostgreSQL databases via "borgmatic restore" action. See the
documentation for more information: documentation for more information:

View file

@ -55,7 +55,7 @@ def extract_archive(
dry_run, dry_run,
repository, repository,
archive, archive,
restore_paths, paths,
location_config, location_config,
storage_config, storage_config,
local_path='borg', local_path='borg',
@ -83,7 +83,7 @@ def extract_archive(
+ (('--dry-run',) if dry_run else ()) + (('--dry-run',) if dry_run else ())
+ (('--progress',) if progress else ()) + (('--progress',) if progress else ())
+ ('::'.join((os.path.abspath(repository), archive)),) + ('::'.join((os.path.abspath(repository), archive)),)
+ (tuple(restore_paths) if restore_paths else ()) + (tuple(paths) if paths else ())
) )
# The progress output isn't compatible with captured and logged output, as progress messes with # The progress output isn't compatible with captured and logged output, as progress messes with

View file

@ -275,11 +275,18 @@ def parse_arguments(*unparsed_arguments):
) )
extract_group.add_argument('--archive', help='Name of archive to operate on', required=True) extract_group.add_argument('--archive', help='Name of archive to operate on', required=True)
extract_group.add_argument( extract_group.add_argument(
'--path',
'--restore-path', '--restore-path',
metavar='PATH', metavar='PATH',
nargs='+', nargs='+',
dest='restore_paths', dest='paths',
help='Paths to restore from archive, defaults to the entire archive', help='Paths to extract from archive, defaults to the entire archive',
)
extract_group.add_argument(
'--destination',
metavar='PATH',
dest='destination',
help='Directory to extract files into, defaults to the current directory',
) )
extract_group.add_argument( extract_group.add_argument(
'--progress', '--progress',

View file

@ -215,12 +215,12 @@ def run_actions(
global_arguments.dry_run, global_arguments.dry_run,
repository, repository,
arguments['extract'].archive, arguments['extract'].archive,
arguments['extract'].restore_paths, arguments['extract'].paths,
location, location,
storage, storage,
local_path=local_path, local_path=local_path,
remote_path=remote_path, remote_path=remote_path,
destination_path=None, destination_path=arguments['extract'].destination,
progress=arguments['extract'].progress, progress=arguments['extract'].progress,
) )
if 'restore' in arguments: if 'restore' in arguments:

View file

@ -51,11 +51,11 @@ borgmatic extract --repository repo.borg --archive host-2019-...
## Extract particular files ## Extract particular files
Sometimes, you want to extract a single deleted file, rather than extracting Sometimes, you want to extract a single deleted file, rather than extracting
everything from an archive. To do that, tack on one or more `--restore-path` everything from an archive. To do that, tack on one or more `--path` values.
values. For instance: For instance:
```bash ```bash
borgmatic extract --archive host-2019-... --restore-path path/1 path/2 borgmatic extract --archive host-2019-... --path path/1 path/2
``` ```
Note that the specified restore paths should not have a leading slash. Like a Note that the specified restore paths should not have a leading slash. Like a
@ -63,6 +63,19 @@ whole-archive extract, this also extracts into the current directory. So for
example, if you happen to be in the directory `/var` and you run the `extract` example, if you happen to be in the directory `/var` and you run the `extract`
command above, borgmatic will extract `/var/path/1` and `/var/path/2`. command above, borgmatic will extract `/var/path/1` and `/var/path/2`.
## Extract to a particular destination
By default, borgmatic extracts files into the current directory. To instead
extract files to a particular destination directory, use the `--destination`
flag:
```bash
borgmatic extract --archive host-2019-... --destination /tmp
```
When using the `--destination` flag, be careful not to overwrite your system's
files with extracted files unless that is your intent.
## Database restoration ## Database restoration

View file

@ -1,6 +1,6 @@
from setuptools import find_packages, setup from setuptools import find_packages, setup
VERSION = '1.4.1' VERSION = '1.4.2'
setup( setup(

View file

@ -267,11 +267,11 @@ def test_parse_arguments_disallows_archive_without_extract_restore_or_list():
module.parse_arguments('--config', 'myconfig', '--archive', 'test') module.parse_arguments('--config', 'myconfig', '--archive', 'test')
def test_parse_arguments_disallows_restore_paths_without_extract(): def test_parse_arguments_disallows_paths_without_extract():
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default']) flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
with pytest.raises(SystemExit): with pytest.raises(SystemExit):
module.parse_arguments('--config', 'myconfig', '--restore-path', 'test') module.parse_arguments('--config', 'myconfig', '--path', 'test')
def test_parse_arguments_allows_archive_with_extract(): def test_parse_arguments_allows_archive_with_extract():

View file

@ -95,7 +95,7 @@ def test_extract_archive_calls_borg_with_restore_path_parameters():
dry_run=False, dry_run=False,
repository='repo', repository='repo',
archive='archive', archive='archive',
restore_paths=['path1', 'path2'], paths=['path1', 'path2'],
location_config={}, location_config={},
storage_config={}, storage_config={},
) )
@ -109,7 +109,7 @@ def test_extract_archive_calls_borg_with_remote_path_parameters():
dry_run=False, dry_run=False,
repository='repo', repository='repo',
archive='archive', archive='archive',
restore_paths=None, paths=None,
location_config={}, location_config={},
storage_config={}, storage_config={},
remote_path='borg1', remote_path='borg1',
@ -124,7 +124,7 @@ def test_extract_archive_calls_borg_with_numeric_owner_parameter():
dry_run=False, dry_run=False,
repository='repo', repository='repo',
archive='archive', archive='archive',
restore_paths=None, paths=None,
location_config={'numeric_owner': True}, location_config={'numeric_owner': True},
storage_config={}, storage_config={},
) )
@ -138,7 +138,7 @@ def test_extract_archive_calls_borg_with_umask_parameters():
dry_run=False, dry_run=False,
repository='repo', repository='repo',
archive='archive', archive='archive',
restore_paths=None, paths=None,
location_config={}, location_config={},
storage_config={'umask': '0770'}, storage_config={'umask': '0770'},
) )
@ -152,7 +152,7 @@ def test_extract_archive_calls_borg_with_lock_wait_parameters():
dry_run=False, dry_run=False,
repository='repo', repository='repo',
archive='archive', archive='archive',
restore_paths=None, paths=None,
location_config={}, location_config={},
storage_config={'lock_wait': '5'}, storage_config={'lock_wait': '5'},
) )
@ -167,7 +167,7 @@ def test_extract_archive_with_log_info_calls_borg_with_info_parameter():
dry_run=False, dry_run=False,
repository='repo', repository='repo',
archive='archive', archive='archive',
restore_paths=None, paths=None,
location_config={}, location_config={},
storage_config={}, storage_config={},
) )
@ -184,7 +184,7 @@ def test_extract_archive_with_log_debug_calls_borg_with_debug_parameters():
dry_run=False, dry_run=False,
repository='repo', repository='repo',
archive='archive', archive='archive',
restore_paths=None, paths=None,
location_config={}, location_config={},
storage_config={}, storage_config={},
) )
@ -198,7 +198,7 @@ def test_extract_archive_calls_borg_with_dry_run_parameter():
dry_run=True, dry_run=True,
repository='repo', repository='repo',
archive='archive', archive='archive',
restore_paths=None, paths=None,
location_config={}, location_config={},
storage_config={}, storage_config={},
) )
@ -212,7 +212,7 @@ def test_extract_archive_calls_borg_with_destination_path():
dry_run=False, dry_run=False,
repository='repo', repository='repo',
archive='archive', archive='archive',
restore_paths=None, paths=None,
location_config={}, location_config={},
storage_config={}, storage_config={},
destination_path='/dest', destination_path='/dest',
@ -231,7 +231,7 @@ def test_extract_archive_calls_borg_with_progress_parameter():
dry_run=False, dry_run=False,
repository='repo', repository='repo',
archive='archive', archive='archive',
restore_paths=None, paths=None,
location_config={}, location_config={},
storage_config={}, storage_config={},
progress=True, progress=True,