Преглед на файлове

Merge pull request #6792 from ThomasWaldmann/check-always-glob-borg2

borg check: remove --name, better use -a
TW преди 3 години
родител
ревизия
e535a99c7a
променени са 2 файла, в които са добавени 17 реда и са изтрити 29 реда
  1. 14 24
      src/borg/archive.py
  2. 3 5
      src/borg/archiver.py

+ 14 - 24
src/borg/archive.py

@@ -1534,19 +1534,18 @@ class ArchiveChecker:
         self.error_found = False
         self.error_found = False
         self.possibly_superseded = set()
         self.possibly_superseded = set()
 
 
-    def check(self, repository, repair=False, archive=None, first=0, last=0, sort_by='', glob=None,
+    def check(self, repository, repair=False, first=0, last=0, sort_by='', glob=None,
               verify_data=False, save_space=False):
               verify_data=False, save_space=False):
         """Perform a set of checks on 'repository'
         """Perform a set of checks on 'repository'
 
 
         :param repair: enable repair mode, write updated or corrected data into repository
         :param repair: enable repair mode, write updated or corrected data into repository
-        :param archive: only check this archive
         :param first/last/sort_by: only check this number of first/last archives ordered by sort_by
         :param first/last/sort_by: only check this number of first/last archives ordered by sort_by
         :param glob: only check archives matching this glob
         :param glob: only check archives matching this glob
         :param verify_data: integrity verification of data referenced by archives
         :param verify_data: integrity verification of data referenced by archives
         :param save_space: Repository.commit(save_space)
         :param save_space: Repository.commit(save_space)
         """
         """
         logger.info('Starting archive consistency check...')
         logger.info('Starting archive consistency check...')
-        self.check_all = archive is None and not any((first, last, glob))
+        self.check_all = not any((first, last, glob))
         self.repair = repair
         self.repair = repair
         self.repository = repository
         self.repository = repository
         self.init_chunks()
         self.init_chunks()
@@ -1568,7 +1567,7 @@ class ArchiveChecker:
                 self.error_found = True
                 self.error_found = True
                 del self.chunks[Manifest.MANIFEST_ID]
                 del self.chunks[Manifest.MANIFEST_ID]
                 self.manifest = self.rebuild_manifest()
                 self.manifest = self.rebuild_manifest()
-        self.rebuild_refcounts(archive=archive, first=first, last=last, sort_by=sort_by, glob=glob)
+        self.rebuild_refcounts(glob=glob, first=first, last=last, sort_by=sort_by)
         self.orphan_chunks_check()
         self.orphan_chunks_check()
         self.finish(save_space=save_space)
         self.finish(save_space=save_space)
         if self.error_found:
         if self.error_found:
@@ -1738,7 +1737,7 @@ class ArchiveChecker:
         logger.info('Manifest rebuild complete.')
         logger.info('Manifest rebuild complete.')
         return manifest
         return manifest
 
 
-    def rebuild_refcounts(self, archive=None, first=0, last=0, sort_by='', glob=None):
+    def rebuild_refcounts(self, first=0, last=0, sort_by='', glob=None):
         """Rebuild object reference counts by walking the metadata
         """Rebuild object reference counts by walking the metadata
 
 
         Missing and/or incorrect data is repaired when detected
         Missing and/or incorrect data is repaired when detected
@@ -1909,26 +1908,17 @@ class ArchiveChecker:
                         raise
                         raise
                     i += 1
                     i += 1
 
 
-        if archive is None:
-            sort_by = sort_by.split(',')
-            if any((first, last, glob)):
-                archive_infos = self.manifest.archives.list(sort_by=sort_by, glob=glob, first=first, last=last)
-                if glob and not archive_infos:
-                    logger.warning('--glob-archives %s does not match any archives', glob)
-                if first and len(archive_infos) < first:
-                    logger.warning('--first %d archives: only found %d archives', first, len(archive_infos))
-                if last and len(archive_infos) < last:
-                    logger.warning('--last %d archives: only found %d archives', last, len(archive_infos))
-            else:
-                archive_infos = self.manifest.archives.list(sort_by=sort_by)
+        sort_by = sort_by.split(',')
+        if any((first, last, glob)):
+            archive_infos = self.manifest.archives.list(sort_by=sort_by, glob=glob, first=first, last=last)
+            if glob and not archive_infos:
+                logger.warning('--glob-archives %s does not match any archives', glob)
+            if first and len(archive_infos) < first:
+                logger.warning('--first %d archives: only found %d archives', first, len(archive_infos))
+            if last and len(archive_infos) < last:
+                logger.warning('--last %d archives: only found %d archives', last, len(archive_infos))
         else:
         else:
-            # we only want one specific archive
-            try:
-                archive_infos = [self.manifest.archives[archive]]
-            except KeyError:
-                logger.error("Archive '%s' not found.", archive)
-                self.error_found = True
-                return
+            archive_infos = self.manifest.archives.list(sort_by=sort_by)
         num_archives = len(archive_infos)
         num_archives = len(archive_infos)
 
 
         pi = ProgressIndicatorPercent(total=num_archives, msg='Checking archives %3.1f%%', step=0.1,
         pi = ProgressIndicatorPercent(total=num_archives, msg='Checking archives %3.1f%%', step=0.1,

+ 3 - 5
src/borg/archiver.py

@@ -525,7 +525,8 @@ class Archiver:
                 return EXIT_ERROR
                 return EXIT_ERROR
         if args.repo_only and any(
         if args.repo_only and any(
            (args.verify_data, args.first, args.last, args.prefix is not None, args.glob_archives)):
            (args.verify_data, args.first, args.last, args.prefix is not None, args.glob_archives)):
-            self.print_error("--repository-only contradicts --first, --last, --prefix and --verify-data arguments.")
+            self.print_error("--repository-only contradicts --first, --last, --prefix, --glob-archives "
+                             " and --verify-data arguments.")
             return EXIT_ERROR
             return EXIT_ERROR
         if args.repair and args.max_duration:
         if args.repair and args.max_duration:
             self.print_error("--repair does not allow --max-duration argument.")
             self.print_error("--repair does not allow --max-duration argument.")
@@ -542,8 +543,7 @@ class Archiver:
                 return EXIT_WARNING
                 return EXIT_WARNING
         if args.prefix is not None:
         if args.prefix is not None:
             args.glob_archives = args.prefix + '*'
             args.glob_archives = args.prefix + '*'
-        if not args.repo_only and not ArchiveChecker().check(
-                repository, repair=args.repair, archive=args.name,
+        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,
                 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):
                 verify_data=args.verify_data, save_space=args.save_space):
             return EXIT_WARNING
             return EXIT_WARNING
@@ -3501,8 +3501,6 @@ class Archiver:
                                           formatter_class=argparse.RawDescriptionHelpFormatter,
                                           formatter_class=argparse.RawDescriptionHelpFormatter,
                                           help='verify repository')
                                           help='verify repository')
         subparser.set_defaults(func=self.do_check)
         subparser.set_defaults(func=self.do_check)
-        subparser.add_argument('--name', dest='name', metavar='NAME', type=NameSpec,
-                               help='specify the archive name')
         subparser.add_argument('--repository-only', dest='repo_only', action='store_true',
         subparser.add_argument('--repository-only', dest='repo_only', action='store_true',
                                help='only perform repository checks')
                                help='only perform repository checks')
         subparser.add_argument('--archives-only', dest='archives_only', action='store_true',
         subparser.add_argument('--archives-only', dest='archives_only', action='store_true',