mirror of
https://github.com/borgbackup/borg.git
synced 2025-02-24 07:01:59 +00:00
debug-get-obj command
This commit is contained in:
parent
a2fc479da3
commit
37c8aa2d42
2 changed files with 43 additions and 2 deletions
|
@ -515,6 +515,26 @@ def do_debug_dump_archive_items(self, args):
|
||||||
print('Done.')
|
print('Done.')
|
||||||
return EXIT_SUCCESS
|
return EXIT_SUCCESS
|
||||||
|
|
||||||
|
def do_debug_get_obj(self, args):
|
||||||
|
"""get object contents from the repository and write it into file"""
|
||||||
|
repository = self.open_repository(args.repository)
|
||||||
|
manifest, key = Manifest.load(repository)
|
||||||
|
hex_id = args.id
|
||||||
|
try:
|
||||||
|
id = unhexlify(hex_id)
|
||||||
|
except ValueError:
|
||||||
|
print("object id %s is invalid." % hex_id)
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
data =repository.get(id)
|
||||||
|
except repository.ObjectNotFound:
|
||||||
|
print("object %s not found." % hex_id)
|
||||||
|
else:
|
||||||
|
with open(args.path, "wb") as f:
|
||||||
|
f.write(data)
|
||||||
|
print("object %s fetched." % hex_id)
|
||||||
|
return EXIT_SUCCESS
|
||||||
|
|
||||||
def do_debug_put_obj(self, args):
|
def do_debug_put_obj(self, args):
|
||||||
"""put file(s) contents into the repository"""
|
"""put file(s) contents into the repository"""
|
||||||
repository = self.open_repository(args.repository)
|
repository = self.open_repository(args.repository)
|
||||||
|
@ -1048,6 +1068,22 @@ def build_parser(self, args=None, prog=None):
|
||||||
type=location_validator(archive=True),
|
type=location_validator(archive=True),
|
||||||
help='archive to dump')
|
help='archive to dump')
|
||||||
|
|
||||||
|
debug_get_obj_epilog = textwrap.dedent("""
|
||||||
|
This command gets an object from the repository.
|
||||||
|
""")
|
||||||
|
subparser = subparsers.add_parser('debug-get-obj', parents=[common_parser],
|
||||||
|
description=self.do_debug_get_obj.__doc__,
|
||||||
|
epilog=debug_get_obj_epilog,
|
||||||
|
formatter_class=argparse.RawDescriptionHelpFormatter)
|
||||||
|
subparser.set_defaults(func=self.do_debug_get_obj)
|
||||||
|
subparser.add_argument('repository', metavar='REPOSITORY', nargs='?', default='',
|
||||||
|
type=location_validator(archive=False),
|
||||||
|
help='repository to use')
|
||||||
|
subparser.add_argument('id', metavar='ID', type=str,
|
||||||
|
help='hex object ID to get from the repo')
|
||||||
|
subparser.add_argument('path', metavar='PATH', type=str,
|
||||||
|
help='file to write object data into')
|
||||||
|
|
||||||
debug_put_obj_epilog = textwrap.dedent("""
|
debug_put_obj_epilog = textwrap.dedent("""
|
||||||
This command puts objects into the repository.
|
This command puts objects into the repository.
|
||||||
""")
|
""")
|
||||||
|
|
|
@ -777,13 +777,18 @@ def test_debug_dump_archive_items(self):
|
||||||
assert len(output_dir) > 0 and output_dir[0].startswith('000000_')
|
assert len(output_dir) > 0 and output_dir[0].startswith('000000_')
|
||||||
assert 'Done.' in output
|
assert 'Done.' in output
|
||||||
|
|
||||||
def test_debug_put_delete_obj(self):
|
def test_debug_put_get_delete_obj(self):
|
||||||
self.cmd('init', self.repository_location)
|
self.cmd('init', self.repository_location)
|
||||||
data = b'some data'
|
data = b'some data'
|
||||||
hexkey = sha256(data).hexdigest()
|
hexkey = sha256(data).hexdigest()
|
||||||
self.create_regular_file('file', contents=data)
|
self.create_regular_file('file', contents=data)
|
||||||
output = self.cmd('debug-put-obj', self.repository_location, 'input/file')
|
output = self.cmd('debug-put-obj', self.repository_location, 'input/file')
|
||||||
assert hexkey in output
|
assert hexkey in output
|
||||||
|
output = self.cmd('debug-get-obj', self.repository_location, hexkey, 'output/file')
|
||||||
|
assert hexkey in output
|
||||||
|
with open('output/file', 'rb') as f:
|
||||||
|
data_read = f.read()
|
||||||
|
assert data == data_read
|
||||||
output = self.cmd('debug-delete-obj', self.repository_location, hexkey)
|
output = self.cmd('debug-delete-obj', self.repository_location, hexkey)
|
||||||
assert "deleted" in output
|
assert "deleted" in output
|
||||||
output = self.cmd('debug-delete-obj', self.repository_location, hexkey)
|
output = self.cmd('debug-delete-obj', self.repository_location, hexkey)
|
||||||
|
@ -901,5 +906,5 @@ def test_fuse_mount_archive(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@unittest.skip('only works locally')
|
@unittest.skip('only works locally')
|
||||||
def test_debug_put_delete_obj(self):
|
def test_debug_put_get_delete_obj(self):
|
||||||
pass
|
pass
|
||||||
|
|
Loading…
Reference in a new issue