Przeglądaj źródła

borg recreate -a ARCHIVE_GLOB ...

Thomas Waldmann 3 lat temu
rodzic
commit
f8d2024578
3 zmienionych plików z 30 dodań i 38 usunięć
  1. 9 19
      src/borg/archiver.py
  2. 5 3
      src/borg/helpers/manifest.py
  3. 16 16
      src/borg/testsuite/archiver.py

+ 9 - 19
src/borg/archiver.py

@@ -2005,25 +2005,16 @@ class Archiver:
                                      checkpoint_interval=args.checkpoint_interval,
                                      dry_run=args.dry_run, timestamp=args.timestamp)
 
-        if args.name:
-            name = args.name
+        archive_names = tuple(archive.name for archive in manifest.archives.list_considering(args))
+        if args.target is not None and len(archive_names) != 1:
+            self.print_error('--target: Need to specify single archive')
+            return self.exit_code
+        for name in archive_names:
             if recreater.is_temporary_archive(name):
-                self.print_error('Refusing to work on temporary archive of prior recreate: %s', name)
-                return self.exit_code
+                continue
+            print('Processing', name)
             if not recreater.recreate(name, args.comment, args.target):
-                self.print_error('Nothing to do. Archive was not processed.\n'
-                                 'Specify at least one pattern, PATH, --comment, re-compression or re-chunking option.')
-        else:
-            if args.target is not None:
-                self.print_error('--target: Need to specify single archive')
-                return self.exit_code
-            for archive in manifest.archives.list(sort_by=['ts']):
-                name = archive.name
-                if recreater.is_temporary_archive(name):
-                    continue
-                print('Processing', name)
-                if not recreater.recreate(name, args.comment):
-                    logger.info('Skipped archive %s: Nothing to do. Archive was not processed.', name)
+                logger.info('Skipped archive %s: Nothing to do. Archive was not processed.', name)
         if not args.dry_run:
             manifest.write()
             repository.commit(compact=False)
@@ -4946,6 +4937,7 @@ class Archiver:
         define_exclusion_group(subparser, tag_files=True)
 
         archive_group = subparser.add_argument_group('Archive options')
+        define_archive_filters_group(archive_group)
         archive_group.add_argument('--target', dest='target', metavar='TARGET', default=None,
                                    type=archivename_validator(),
                                    help='create a new archive with the name ARCHIVE, do not replace existing archive '
@@ -4981,8 +4973,6 @@ class Archiver:
                                         'HASH_MASK_BITS, HASH_WINDOW_SIZE) or `default` to use the current defaults. '
                                         'default: %s,%d,%d,%d,%d' % CHUNKER_PARAMS)
 
-        subparser.add_argument('--name', dest='name', metavar='NAME', type=NameSpec,
-                               help='specify the archive name')
         subparser.add_argument('paths', metavar='PATH', nargs='*', type=str,
                                help='paths to recreate; patterns are supported')
 

+ 5 - 3
src/borg/helpers/manifest.py

@@ -103,11 +103,13 @@ class Archives(abc.MutableMapping):
         """
         get a list of archives, considering --first/last/prefix/glob-archives/sort/consider-checkpoints cmdline args
         """
-        if args.name:
-            raise Error('The options --first, --last, --prefix, and --glob-archives, and --consider-checkpoints can only be used on repository targets.')
+        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 + '*'
-        return self.list(sort_by=args.sort_by.split(','), consider_checkpoints=args.consider_checkpoints, glob=args.glob_archives, first=args.first, last=args.last)
+        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):
         """set the dict we get from the msgpack unpacker"""

+ 16 - 16
src/borg/testsuite/archiver.py

@@ -1314,7 +1314,7 @@ class ArchiverTestCase(ArchiverTestCaseBase):
     def test_recreate_exclude_caches(self):
         self._create_test_caches()
         self.cmd(f'--repo={self.repository_location}', 'create', 'test', 'input')
-        self.cmd(f'--repo={self.repository_location}', 'recreate', '--name=test', '--exclude-caches')
+        self.cmd(f'--repo={self.repository_location}', 'recreate', '-a', 'test', '--exclude-caches')
         self._assert_test_caches()
 
     def _create_test_tagged(self):
@@ -1338,7 +1338,7 @@ class ArchiverTestCase(ArchiverTestCaseBase):
     def test_recreate_exclude_tagged(self):
         self._create_test_tagged()
         self.cmd(f'--repo={self.repository_location}', 'create', 'test', 'input')
-        self.cmd(f'--repo={self.repository_location}', 'recreate', '--name=test', '--exclude-if-present', '.NOBACKUP',
+        self.cmd(f'--repo={self.repository_location}', 'recreate', '-a', 'test', '--exclude-if-present', '.NOBACKUP',
                  '--exclude-if-present', '00-NOBACKUP')
         self._assert_test_tagged()
 
@@ -1377,7 +1377,7 @@ class ArchiverTestCase(ArchiverTestCaseBase):
     def test_recreate_exclude_keep_tagged(self):
         self._create_test_keep_tagged()
         self.cmd(f'--repo={self.repository_location}', 'create', 'test', 'input')
-        self.cmd(f'--repo={self.repository_location}', 'recreate', '--name=test', '--exclude-if-present', '.NOBACKUP1',
+        self.cmd(f'--repo={self.repository_location}', 'recreate', '-a', 'test', '--exclude-if-present', '.NOBACKUP1',
                  '--exclude-if-present', '.NOBACKUP2', '--exclude-caches', '--keep-exclude-tags')
         self._assert_test_keep_tagged()
 
@@ -1392,7 +1392,7 @@ class ArchiverTestCase(ArchiverTestCaseBase):
         # in the "test" archive, we now have, in this order:
         # - a regular file item for "file1"
         # - a hardlink item for "CACHEDIR.TAG" referring back to file1 for its contents
-        self.cmd(f'--repo={self.repository_location}', 'recreate', '--name=test', '--exclude-caches', '--keep-exclude-tags')
+        self.cmd(f'--repo={self.repository_location}', 'recreate', 'test', '--exclude-caches', '--keep-exclude-tags')
         # if issue #4911 is present, the recreate will crash with a KeyError for "input/file1"
 
     @pytest.mark.skipif(not xattr.XATTR_FAKEROOT, reason='Linux capabilities test, requires fakeroot >= 1.20.2')
@@ -1579,10 +1579,10 @@ class ArchiverTestCase(ArchiverTestCaseBase):
         assert 'Comment: \n' in self.cmd(f'--repo={self.repository_location}', 'info', '--name=test1')
         assert 'Comment: this is the comment' in self.cmd(f'--repo={self.repository_location}', 'info', '--name=test2')
 
-        self.cmd(f'--repo={self.repository_location}', 'recreate', '--name=test1', '--comment', 'added comment')
-        self.cmd(f'--repo={self.repository_location}', 'recreate', '--name=test2', '--comment', 'modified comment')
-        self.cmd(f'--repo={self.repository_location}', 'recreate', '--name=test3', '--comment', '')
-        self.cmd(f'--repo={self.repository_location}', 'recreate', '--name=test4', '12345')
+        self.cmd(f'--repo={self.repository_location}', 'recreate', '-a', 'test1', '--comment', 'added comment')
+        self.cmd(f'--repo={self.repository_location}', 'recreate', '-a', 'test2', '--comment', 'modified comment')
+        self.cmd(f'--repo={self.repository_location}', 'recreate', '-a', 'test3', '--comment', '')
+        self.cmd(f'--repo={self.repository_location}', 'recreate', '-a', 'test4', '12345')
         assert 'Comment: added comment' in self.cmd(f'--repo={self.repository_location}', 'info', '--name=test1')
         assert 'Comment: modified comment' in self.cmd(f'--repo={self.repository_location}', 'info', '--name=test2')
         assert 'Comment: \n' in self.cmd(f'--repo={self.repository_location}', 'info', '--name=test3')
@@ -2921,7 +2921,7 @@ class ArchiverTestCase(ArchiverTestCaseBase):
         self.cmd(f'--repo={self.repository_location}', 'create', 'test0', 'input')
         self.check_cache()
         original_archive = self.cmd(f'--repo={self.repository_location}', 'list')
-        self.cmd(f'--repo={self.repository_location}', 'recreate', '--name=test0', 'input/dir2',
+        self.cmd(f'--repo={self.repository_location}', 'recreate', 'test0', 'input/dir2',
                  '-e', 'input/dir2/file3', '--target=new-archive')
         self.check_cache()
         archives = self.cmd(f'--repo={self.repository_location}', 'list')
@@ -2938,7 +2938,7 @@ class ArchiverTestCase(ArchiverTestCaseBase):
         self.create_regular_file('dir2/file3', size=1024 * 80)
         self.cmd(f'--repo={self.repository_location}', 'init', '--encryption=repokey')
         self.cmd(f'--repo={self.repository_location}', 'create', 'test0', 'input')
-        self.cmd(f'--repo={self.repository_location}', 'recreate', '--name=test0', 'input/dir2', '-e', 'input/dir2/file3')
+        self.cmd(f'--repo={self.repository_location}', 'recreate', 'test0', 'input/dir2', '-e', 'input/dir2/file3')
         self.check_cache()
         listing = self.cmd(f'--repo={self.repository_location}', 'list', '--name=test0', '--short')
         assert 'file1' not in listing
@@ -2950,7 +2950,7 @@ class ArchiverTestCase(ArchiverTestCaseBase):
         # This is essentially the same problem set as in test_extract_hardlinks
         self._extract_hardlinks_setup()
         self.cmd(f'--repo={self.repository_location}', 'create', 'test2', 'input')
-        self.cmd(f'--repo={self.repository_location}', 'recreate', '--name=test', 'input/dir1')
+        self.cmd(f'--repo={self.repository_location}', 'recreate', '-a', 'test', 'input/dir1')
         self.check_cache()
         with changedir('output'):
             self.cmd(f'--repo={self.repository_location}', 'extract', '--name=test')
@@ -3000,7 +3000,7 @@ class ArchiverTestCase(ArchiverTestCaseBase):
         self.create_test_files()
         self.cmd(f'--repo={self.repository_location}', 'init', '--encryption=repokey')
         self.cmd(f'--repo={self.repository_location}', 'create', 'test0', 'input')
-        self.cmd(f'--repo={self.repository_location}', 'recreate', '--name=test0', '--timestamp', "1970-01-02T00:00:00",
+        self.cmd(f'--repo={self.repository_location}', 'recreate', 'test0', '--timestamp', "1970-01-02T00:00:00",
                  '--comment', 'test')
         info = self.cmd(f'--repo={self.repository_location}', 'info', '--name=test0').splitlines()
         dtime = datetime(1970, 1, 2) + local_timezone.utcoffset(None)
@@ -3044,22 +3044,22 @@ class ArchiverTestCase(ArchiverTestCaseBase):
 
         self.cmd(f'--repo={self.repository_location}', 'create', 'test', 'input')
 
-        output = self.cmd(f'--repo={self.repository_location}', 'recreate', '--name=test', '--list', '--info', '-e', 'input/file2')
+        output = self.cmd(f'--repo={self.repository_location}', 'recreate', '-a', 'test', '--list', '--info', '-e', 'input/file2')
         self.check_cache()
         self.assert_in("input/file1", output)
         self.assert_in("x input/file2", output)
 
-        output = self.cmd(f'--repo={self.repository_location}', 'recreate', '--name=test', '--list', '-e', 'input/file3')
+        output = self.cmd(f'--repo={self.repository_location}', 'recreate', '-a', 'test', '--list', '-e', 'input/file3')
         self.check_cache()
         self.assert_in("input/file1", output)
         self.assert_in("x input/file3", output)
 
-        output = self.cmd(f'--repo={self.repository_location}', 'recreate', '--name=test', '-e', 'input/file4')
+        output = self.cmd(f'--repo={self.repository_location}', 'recreate', '-a', 'test', '-e', 'input/file4')
         self.check_cache()
         self.assert_not_in("input/file1", output)
         self.assert_not_in("x input/file4", output)
 
-        output = self.cmd(f'--repo={self.repository_location}', 'recreate', '--name=test', '--info', '-e', 'input/file5')
+        output = self.cmd(f'--repo={self.repository_location}', 'recreate', '-a', 'test', '--info', '-e', 'input/file5')
         self.check_cache()
         self.assert_not_in("input/file1", output)
         self.assert_not_in("x input/file5", output)