diff --git a/borg/archiver.py b/borg/archiver.py index e18ded6c6..8432a78de 100644 --- a/borg/archiver.py +++ b/borg/archiver.py @@ -414,6 +414,8 @@ class Archiver: remove_surrogates(item[b'path']), extra)) else: for archive_info in manifest.list_archive_infos(sort_by='ts'): + if args.prefix and not archive_info.name.startswith(args.prefix): + continue print(format_archive(archive_info)) return self.exit_code @@ -835,9 +837,12 @@ class Archiver: subparser.add_argument('--short', dest='short', action='store_true', default=False, help='only print file/directory names, nothing else') + subparser.add_argument('-p', '--prefix', dest='prefix', type=str, + help='only consider archive names starting with this prefix') subparser.add_argument('src', metavar='REPOSITORY_OR_ARCHIVE', nargs='?', default='', type=location_validator(), help='repository/archive to list contents of') + mount_epilog = textwrap.dedent(""" This command mounts an archive as a FUSE filesystem. This can be useful for browsing an archive or restoring individual files. Unless the ``--foreground`` diff --git a/borg/testsuite/archiver.py b/borg/testsuite/archiver.py index 61d954e67..780a976ef 100644 --- a/borg/testsuite/archiver.py +++ b/borg/testsuite/archiver.py @@ -675,6 +675,16 @@ class ArchiverTestCase(ArchiverTestCaseBase): self.assert_in('bar-2015-08-12-10:00', output) self.assert_in('bar-2015-08-12-20:00', output) + def test_list_prefix(self): + self.cmd('init', self.repository_location) + self.cmd('create', self.repository_location + '::test-1', src_dir) + self.cmd('create', self.repository_location + '::something-else-than-test-1', src_dir) + self.cmd('create', self.repository_location + '::test-2', src_dir) + output = self.cmd('list', '--prefix=test-', self.repository_location) + self.assert_in('test-1', output) + self.assert_in('test-2', output) + self.assert_not_in('something-else', output) + def test_usage(self): if self.FORK_DEFAULT: self.cmd(exit_code=0)