Browse Source

Merge pull request #5662 from ThomasWaldmann/dump-hints

implement borg debug dump-hints
TW 4 years ago
parent
commit
9c988ee632
1 changed files with 34 additions and 1 deletions
  1. 34 1
      src/borg/archiver.py

+ 34 - 1
src/borg/archiver.py

@@ -24,7 +24,7 @@ try:
     import tarfile
     import tarfile
     import textwrap
     import textwrap
     import time
     import time
-    from binascii import unhexlify
+    from binascii import unhexlify, hexlify
     from contextlib import contextmanager
     from contextlib import contextmanager
     from datetime import datetime, timedelta
     from datetime import datetime, timedelta
     from io import TextIOWrapper
     from io import TextIOWrapper
@@ -2129,6 +2129,24 @@ class Archiver:
                     print("object %s not found [info from chunks cache]." % hex_id)
                     print("object %s not found [info from chunks cache]." % hex_id)
         return EXIT_SUCCESS
         return EXIT_SUCCESS
 
 
+    @with_repository(manifest=False, exclusive=True)
+    def do_debug_dump_hints(self, args, repository):
+        """dump repository hints"""
+        if not repository._active_txn:
+            repository.prepare_txn(repository.get_transaction_id())
+        try:
+            hints = dict(
+                segments=repository.segments,
+                compact=repository.compact,
+                storage_quota_use=repository.storage_quota_use,
+                shadow_index={hexlify(k).decode(): v for k, v in repository.shadow_index.items()}
+            )
+            with dash_open(args.path, 'w') as fd:
+                json.dump(hints, fd, indent=4)
+        finally:
+            repository.rollback()
+        return EXIT_SUCCESS
+
     def do_debug_convert_profile(self, args):
     def do_debug_convert_profile(self, args):
         """convert Borg profile to Python profile"""
         """convert Borg profile to Python profile"""
         import marshal
         import marshal
@@ -3559,6 +3577,21 @@ class Archiver:
         subparser.add_argument('ids', metavar='IDs', nargs='+', type=str,
         subparser.add_argument('ids', metavar='IDs', nargs='+', type=str,
                                help='hex object ID(s) to show refcounts for')
                                help='hex object ID(s) to show refcounts for')
 
 
+        debug_dump_hints_epilog = process_epilog("""
+        This command dumps the repository hints data.
+        """)
+        subparser = debug_parsers.add_parser('dump-hints', parents=[common_parser], add_help=False,
+                                          description=self.do_debug_dump_hints.__doc__,
+                                          epilog=debug_dump_hints_epilog,
+                                          formatter_class=argparse.RawDescriptionHelpFormatter,
+                                          help='dump repo hints (debug)')
+        subparser.set_defaults(func=self.do_debug_dump_hints)
+        subparser.add_argument('location', metavar='REPOSITORY',
+                               type=location_validator(archive=False),
+                               help='repository to dump')
+        subparser.add_argument('path', metavar='PATH', type=str,
+                               help='file to dump data into')
+
         debug_convert_profile_epilog = process_epilog("""
         debug_convert_profile_epilog = process_epilog("""
         Convert a Borg profile to a Python cProfile compatible profile.
         Convert a Borg profile to a Python cProfile compatible profile.
         """)
         """)