1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2024-12-27 10:18:12 +00:00

add borg debug refcount-obj ID subcommand

This commit is contained in:
Thomas Waldmann 2016-10-17 03:16:13 +02:00
parent 48bcd2aa9a
commit 498e71846c

View file

@ -808,6 +808,22 @@ def do_debug_delete_obj(self, args, repository):
print('Done.') print('Done.')
return EXIT_SUCCESS return EXIT_SUCCESS
@with_repository(manifest=False, exclusive=True, cache=True)
def do_debug_refcount_obj(self, args, repository, manifest, key, cache):
"""display refcounts for the objects with the given IDs"""
for hex_id in args.ids:
try:
id = unhexlify(hex_id)
except ValueError:
print("object id %s is invalid." % hex_id)
else:
try:
refcount = cache.chunks[id][0]
print("object %s has %d referrers [info from chunks cache]." % (hex_id, refcount))
except KeyError:
print("object %s not found [info from chunks cache]." % hex_id)
return EXIT_SUCCESS
@with_repository(lock=False, manifest=False) @with_repository(lock=False, manifest=False)
def do_break_lock(self, args, repository): def do_break_lock(self, args, repository):
"""Break the repository lock (e.g. in case it was left by a dead borg.""" """Break the repository lock (e.g. in case it was left by a dead borg."""
@ -1782,6 +1798,33 @@ def build_parser(self, args=None, prog=None):
subparser.add_argument('ids', metavar='IDs', nargs='+', type=str, subparser.add_argument('ids', metavar='IDs', nargs='+', type=str,
help='hex object ID(s) to delete from the repo') help='hex object ID(s) to delete from the repo')
debug_refcount_obj_epilog = textwrap.dedent("""
This command displays the reference count for objects from the repository.
""")
subparser = subparsers.add_parser('debug-refcount-obj', parents=[common_parser],
description=self.do_debug_refcount_obj.__doc__,
epilog=debug_refcount_obj_epilog,
formatter_class=argparse.RawDescriptionHelpFormatter,
help='show refcount for object from repository (debug)')
subparser.set_defaults(func=self.do_debug_refcount_obj)
subparser.add_argument('location', metavar='REPOSITORY', nargs='?', default='',
type=location_validator(archive=False),
help='repository to use')
subparser.add_argument('ids', metavar='IDs', nargs='+', type=str,
help='hex object ID(s) to show refcounts for')
subparser = debug_parsers.add_parser('refcount-obj', parents=[common_parser],
description=self.do_debug_refcount_obj.__doc__,
epilog=debug_refcount_obj_epilog,
formatter_class=argparse.RawDescriptionHelpFormatter,
help='show refcount for object from repository (debug)')
subparser.set_defaults(func=self.do_debug_refcount_obj)
subparser.add_argument('location', metavar='REPOSITORY', nargs='?', default='',
type=location_validator(archive=False),
help='repository to use')
subparser.add_argument('ids', metavar='IDs', nargs='+', type=str,
help='hex object ID(s) to show refcounts for')
return parser return parser
def get_args(self, argv, cmd): def get_args(self, argv, cmd):