1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2024-12-25 09:19:31 +00:00

add repository.info(), giving some basic repo infos

there was no way to tell the repository version for a remote repo.
borg 2 needs that to reject doing most operations with an old repo,
except the stuff needed for borg transfer.
This commit is contained in:
Thomas Waldmann 2022-06-30 23:55:51 +02:00
parent 2ab254cea0
commit b0b5a2fd27
3 changed files with 21 additions and 0 deletions

View file

@ -1692,12 +1692,16 @@ def do_rinfo(self, args, repository, manifest, key, cache):
print(textwrap.dedent(""" print(textwrap.dedent("""
Repository ID: {id} Repository ID: {id}
Location: {location} Location: {location}
Repository version: {version}
Append only: {append_only}
{encryption} {encryption}
Cache: {cache.path} Cache: {cache.path}
Security dir: {security_dir} Security dir: {security_dir}
""").strip().format( """).strip().format(
id=bin_to_hex(repository.id), id=bin_to_hex(repository.id),
location=repository._location.canonical_path(), location=repository._location.canonical_path(),
version=repository.version,
append_only=repository.append_only,
**info)) **info))
print(str(cache)) print(str(cache))
return self.exit_code return self.exit_code

View file

@ -133,6 +133,7 @@ def __init__(self, data):
'break_lock': (), 'break_lock': (),
'negotiate': ('client_data', ), 'negotiate': ('client_data', ),
'open': ('path', 'create', 'lock_wait', 'lock', 'exclusive', 'append_only', ), 'open': ('path', 'create', 'lock_wait', 'lock', 'exclusive', 'append_only', ),
'info': (),
'get_free_nonce': (), 'get_free_nonce': (),
'commit_nonce_reservation': ('next_unreserved', 'start_nonce', ), 'commit_nonce_reservation': ('next_unreserved', 'start_nonce', ),
} }
@ -150,6 +151,7 @@ class RepositoryServer: # pragma: no cover
'scan', 'scan',
'negotiate', 'negotiate',
'open', 'open',
'info',
'put', 'put',
'rollback', 'rollback',
'save_key', 'save_key',
@ -580,6 +582,9 @@ def do_open():
self.id = self.open(path=self.location.path, create=create, lock_wait=lock_wait, self.id = self.open(path=self.location.path, create=create, lock_wait=lock_wait,
lock=lock, exclusive=exclusive, append_only=append_only, lock=lock, exclusive=exclusive, append_only=append_only,
make_parent_dirs=make_parent_dirs) make_parent_dirs=make_parent_dirs)
info = self.info()
self.version = info['version']
self.append_only = info['append_only']
if self.dictFormat: if self.dictFormat:
do_open() do_open()
@ -898,6 +903,10 @@ def open(self, path, create=False, lock_wait=None, lock=True, exclusive=False, a
make_parent_dirs=False): make_parent_dirs=False):
"""actual remoting is done via self.call in the @api decorator""" """actual remoting is done via self.call in the @api decorator"""
@api(since=parse_version('2.0.0a3'))
def info(self):
"""actual remoting is done via self.call in the @api decorator"""
@api(since=parse_version('1.0.0'), @api(since=parse_version('1.0.0'),
max_duration={'since': parse_version('1.2.0a4'), 'previously': 0}) max_duration={'since': parse_version('1.2.0a4'), 'previously': 0})
def check(self, repair=False, save_space=False, max_duration=0): def check(self, repair=False, save_space=False, max_duration=0):

View file

@ -491,6 +491,14 @@ def open(self, path, exclusive, lock_wait=None, lock=True):
self.close() self.close()
raise self.AtticRepository(path) raise self.AtticRepository(path)
def info(self):
"""return some infos about the repo (must be opened first)"""
return dict(
id=self.id,
version=self.version,
append_only=self.append_only,
)
def close(self): def close(self):
if self.lock: if self.lock:
if self.io: if self.io: