Repository: borgbackup/borg

Issue:
drop --prefix and only use -a ?
borg2 branch:

borg uses `-a` (aka `--glob-archives`) quite a lot now, basically everywhere, where multiple archive names make sense.

in that context, `--prefix` looks a bit superfluous, because it is just doing `-a 'PREFIX*'` internally.

shall we drop it in borg 2 and people just use `-a 'PREFIX*'` directly?



Discussion:
Yes, deprecate it in maint-1.2 and remove it in 2.0.

Resolving patch:
diff --git a/src/borg/archiver.py b/src/borg/archiver.py
--- a/src/borg/archiver.py
+++ b/src/borg/archiver.py
@@ -459,8 +459,8 @@ def do_check(self, args, repository):
                        env_var_override='BORG_CHECK_I_KNOW_WHAT_I_AM_DOING'):
                 return EXIT_ERROR
         if args.repo_only and any(
-           (args.verify_data, args.first, args.last, args.prefix is not None, args.glob_archives)):
-            self.print_error("--repository-only contradicts --first, --last, --prefix, --glob-archives "
+           (args.verify_data, args.first, args.last, args.glob_archives)):
+            self.print_error("--repository-only contradicts --first, --last, -a / --glob-archives "
                              " and --verify-data arguments.")
             return EXIT_ERROR
         if args.repair and args.max_duration:
@@ -476,8 +476,6 @@ def do_check(self, args, repository):
         if not args.archives_only:
             if not repository.check(repair=args.repair, save_space=args.save_space, max_duration=args.max_duration):
                 return EXIT_WARNING
-        if args.prefix is not None:
-            args.glob_archives = args.prefix + '*'
         if not args.repo_only and not ArchiveChecker().check(repository, repair=args.repair,
                 first=args.first, last=args.last, sort_by=args.sort_by or 'ts', glob=args.glob_archives,
                 verify_data=args.verify_data, save_space=args.save_space):
@@ -1757,8 +1755,6 @@ def do_prune(self, args, repository, manifest, key):
                              '"keep-secondly", "keep-minutely", "keep-hourly", "keep-daily", '
                              '"keep-weekly", "keep-monthly" or "keep-yearly" settings must be specified.')
             return self.exit_code
-        if args.prefix is not None:
-            args.glob_archives = args.prefix + '*'
         checkpoint_re = r'\.checkpoint(\.\d+)?'
         archives_checkpoints = manifest.archives.list(glob=args.glob_archives,
                                                       consider_checkpoints=True,
@@ -2652,7 +2648,7 @@ def do_break_lock(self, args, repository):
         This allows you to share the same patterns between multiple repositories
         without needing to specify them on the command line.\n\n''')
     helptext['placeholders'] = textwrap.dedent('''
-        Repository URLs, ``--name``, ``--prefix``, ``--glob-archives``, ``--comment``
+        Repository URLs, ``--name``, ``-a`` / ``--glob-archives``, ``--comment``
         and ``--remote-path`` values support these placeholders:
 
         {hostname}
@@ -2698,7 +2694,7 @@ def do_break_lock(self, args, repository):
 
             borg create /path/to/repo::{hostname}-{user}-{utcnow} ...
             borg create /path/to/repo::{hostname}-{now:%Y-%m-%d_%H:%M:%S} ...
-            borg prune --prefix '{hostname}-' ...
+            borg prune -a '{hostname}-*' ...
 
         .. note::
             systemd uses a difficult, non-standard syntax for command lines in unit files (refer to
@@ -3091,13 +3087,10 @@ def define_archive_filters_group(subparser, *, sort_by=True, first_last=True):
             filters_group = subparser.add_argument_group('Archive filters',
                                                          'Archive filters can be applied to repository targets.')
             group = filters_group.add_mutually_exclusive_group()
-            group.add_argument('-P', '--prefix', metavar='PREFIX', dest='prefix', type=PrefixSpec, action=Highlander,
-                               help='only consider archive names starting with this prefix.')
             group.add_argument('-a', '--glob-archives', metavar='GLOB', dest='glob_archives',
                                type=GlobSpec, action=Highlander,
                                help='only consider archive names matching the glob. '
-                                    'sh: rules apply, see "borg help patterns". '
-                                    '``--prefix`` and ``--glob-archives`` are mutually exclusive.')
+                                    'sh: rules apply, see "borg help patterns".')
 
             if sort_by:
                 sort_by_default = 'timestamp'
@@ -3971,11 +3964,9 @@ def define_borg_mount(parser):
         that is how much your repository will shrink.
         Please note that the "All archives" stats refer to the state after deletion.
 
-        You can delete multiple archives by specifying their common prefix, if they
-        have one, using the ``--prefix PREFIX`` option. You can also specify a shell
-        pattern to match multiple archives using the ``--glob-archives GLOB`` option
-        (for more info on these patterns, see :ref:`borg_patterns`). Note that these
-        two options are mutually exclusive.
+        You can delete multiple archives by specifying a matching shell pattern,
+        using the ``--glob-archives GLOB`` option (for more info on these patterns,
+        see :ref:`borg_patterns`).
 
         Always first use ``--dry-run --list`` to see what would be deleted.
         """)
diff --git a/src/borg/helpers/manifest.py b/src/borg/helpers/manifest.py
--- a/src/borg/helpers/manifest.py
+++ b/src/borg/helpers/manifest.py
@@ -106,9 +106,7 @@ def list_considering(self, args):
         name = getattr(args, 'name', None)
         consider_checkpoints = getattr(args, 'consider_checkpoints', None)
         if name is not None:
-            raise Error('Giving a specific name is incompatible with options --first, --last, --prefix, and --glob-archives, and --consider-checkpoints.')
-        if args.prefix is not None:
-            args.glob_archives = args.prefix + '*'
+            raise Error('Giving a specific name is incompatible with options --first, --last, -a / --glob-archives, and --consider-checkpoints.')
         return self.list(sort_by=args.sort_by.split(','), consider_checkpoints=consider_checkpoints, glob=args.glob_archives, first=args.first, last=args.last)
 
     def set_raw_dict(self, d):
diff --git a/src/borg/testsuite/archiver.py b/src/borg/testsuite/archiver.py
--- a/src/borg/testsuite/archiver.py
+++ b/src/borg/testsuite/archiver.py
@@ -1600,7 +1600,7 @@ def test_delete(self):
         self.cmd(f'--repo={self.repository_location}', 'create', 'another_test.2', 'input')
         self.cmd(f'--repo={self.repository_location}', 'extract', 'test', '--dry-run')
         self.cmd(f'--repo={self.repository_location}', 'extract', 'test.2', '--dry-run')
-        self.cmd(f'--repo={self.repository_location}', 'delete', '--prefix', 'another_')
+        self.cmd(f'--repo={self.repository_location}', 'delete', '--glob-archives', 'another_*')
         self.cmd(f'--repo={self.repository_location}', 'delete', '--last', '1')
         self.cmd(f'--repo={self.repository_location}', 'delete', '-a', 'test')
         self.cmd(f'--repo={self.repository_location}', 'extract', 'test.2', '--dry-run')
@@ -2259,7 +2259,7 @@ def test_prune_repository_prefix(self):
         self.cmd(f'--repo={self.repository_location}', 'create', 'foo-2015-08-12-20:00', src_dir)
         self.cmd(f'--repo={self.repository_location}', 'create', 'bar-2015-08-12-10:00', src_dir)
         self.cmd(f'--repo={self.repository_location}', 'create', 'bar-2015-08-12-20:00', src_dir)
-        output = self.cmd(f'--repo={self.repository_location}', 'prune', '--list', '--dry-run', '--keep-daily=1', '--prefix=foo-')
+        output = self.cmd(f'--repo={self.repository_location}', 'prune', '--list', '--dry-run', '--keep-daily=1', '--glob-archives=foo-*')
         assert re.search(r'Keeping archive \(rule: daily #1\):\s+foo-2015-08-12-20:00', output)
         assert re.search(r'Would prune:\s+foo-2015-08-12-10:00', output)
         output = self.cmd(f'--repo={self.repository_location}', 'rlist')
@@ -2267,7 +2267,7 @@ def test_prune_repository_prefix(self):
         self.assert_in('foo-2015-08-12-20:00', output)
         self.assert_in('bar-2015-08-12-10:00', output)
         self.assert_in('bar-2015-08-12-20:00', output)
-        self.cmd(f'--repo={self.repository_location}', 'prune', '--keep-daily=1', '--prefix=foo-')
+        self.cmd(f'--repo={self.repository_location}', 'prune', '--keep-daily=1', '--glob-archives=foo-*')
         output = self.cmd(f'--repo={self.repository_location}', 'rlist')
         self.assert_not_in('foo-2015-08-12-10:00', output)
         self.assert_in('foo-2015-08-12-20:00', output)
@@ -2300,7 +2300,7 @@ def test_list_prefix(self):
         self.cmd(f'--repo={self.repository_location}', 'create', 'test-1', src_dir)
         self.cmd(f'--repo={self.repository_location}', 'create', 'something-else-than-test-1', src_dir)
         self.cmd(f'--repo={self.repository_location}', 'create', 'test-2', src_dir)
-        output = self.cmd(f'--repo={self.repository_location}', 'rlist', '--prefix=test-')
+        output = self.cmd(f'--repo={self.repository_location}', 'rlist', '--glob-archives=test-*')
         self.assert_in('test-1', output)
         self.assert_in('test-2', output)
         self.assert_not_in('something-else', output)
@@ -2664,13 +2664,13 @@ def test_fuse_mount_options(self):
             assert sorted(os.listdir(os.path.join(mountpoint))) == ['arch11', 'arch12']
         with self.fuse_mount(self.repository_location, mountpoint, '--last=2', '--sort=name'):
             assert sorted(os.listdir(os.path.join(mountpoint))) == ['arch21', 'arch22']
-        with self.fuse_mount(self.repository_location, mountpoint, '--prefix=arch1'):
+        with self.fuse_mount(self.repository_location, mountpoint, '--glob-archives=arch1*'):
             assert sorted(os.listdir(os.path.join(mountpoint))) == ['arch11', 'arch12']
-        with self.fuse_mount(self.repository_location, mountpoint, '--prefix=arch2'):
+        with self.fuse_mount(self.repository_location, mountpoint, '--glob-archives=arch2*'):
             assert sorted(os.listdir(os.path.join(mountpoint))) == ['arch21', 'arch22']
-        with self.fuse_mount(self.repository_location, mountpoint, '--prefix=arch'):
+        with self.fuse_mount(self.repository_location, mountpoint, '--glob-archives=arch*'):
             assert sorted(os.listdir(os.path.join(mountpoint))) == ['arch11', 'arch12', 'arch21', 'arch22']
-        with self.fuse_mount(self.repository_location, mountpoint, '--prefix=nope'):
+        with self.fuse_mount(self.repository_location, mountpoint, '--glob-archives=nope'):
             assert sorted(os.listdir(os.path.join(mountpoint))) == []
 
     @unittest.skipUnless(llfuse, 'llfuse not installed')
@@ -3559,7 +3559,7 @@ def test_check_usage(self):
         output = self.cmd(f'--repo={self.repository_location}', 'check', '-v', '--archives-only', exit_code=0)
         self.assert_not_in('Starting repository check', output)
         self.assert_in('Starting archive consistency check', output)
-        output = self.cmd(f'--repo={self.repository_location}', 'check', '-v', '--archives-only', '--prefix=archive2', exit_code=0)
+        output = self.cmd(f'--repo={self.repository_location}', 'check', '-v', '--archives-only', '--glob-archives=archive2', exit_code=0)
         self.assert_not_in('archive1', output)
         output = self.cmd(f'--repo={self.repository_location}', 'check', '-v', '--archives-only', '--first=1', exit_code=0)
         self.assert_in('archive1', output)


Test patch: