From b0b5a2fd27aa5a56f7d62434f18f14a9b8e11a26 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Thu, 30 Jun 2022 23:55:51 +0200 Subject: [PATCH 1/2] 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. --- src/borg/archiver.py | 4 ++++ src/borg/remote.py | 9 +++++++++ src/borg/repository.py | 8 ++++++++ 3 files changed, 21 insertions(+) diff --git a/src/borg/archiver.py b/src/borg/archiver.py index d61ead194..816cc9e7e 100644 --- a/src/borg/archiver.py +++ b/src/borg/archiver.py @@ -1692,12 +1692,16 @@ def do_rinfo(self, args, repository, manifest, key, cache): print(textwrap.dedent(""" Repository ID: {id} Location: {location} + Repository version: {version} + Append only: {append_only} {encryption} Cache: {cache.path} Security dir: {security_dir} """).strip().format( id=bin_to_hex(repository.id), location=repository._location.canonical_path(), + version=repository.version, + append_only=repository.append_only, **info)) print(str(cache)) return self.exit_code diff --git a/src/borg/remote.py b/src/borg/remote.py index ac7255aa7..22b078dcd 100644 --- a/src/borg/remote.py +++ b/src/borg/remote.py @@ -133,6 +133,7 @@ def __init__(self, data): 'break_lock': (), 'negotiate': ('client_data', ), 'open': ('path', 'create', 'lock_wait', 'lock', 'exclusive', 'append_only', ), + 'info': (), 'get_free_nonce': (), 'commit_nonce_reservation': ('next_unreserved', 'start_nonce', ), } @@ -150,6 +151,7 @@ class RepositoryServer: # pragma: no cover 'scan', 'negotiate', 'open', + 'info', 'put', 'rollback', 'save_key', @@ -580,6 +582,9 @@ def do_open(): self.id = self.open(path=self.location.path, create=create, lock_wait=lock_wait, lock=lock, exclusive=exclusive, append_only=append_only, make_parent_dirs=make_parent_dirs) + info = self.info() + self.version = info['version'] + self.append_only = info['append_only'] if self.dictFormat: do_open() @@ -898,6 +903,10 @@ def open(self, path, create=False, lock_wait=None, lock=True, exclusive=False, a make_parent_dirs=False): """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'), max_duration={'since': parse_version('1.2.0a4'), 'previously': 0}) def check(self, repair=False, save_space=False, max_duration=0): diff --git a/src/borg/repository.py b/src/borg/repository.py index d31d4a9d6..ba193243c 100644 --- a/src/borg/repository.py +++ b/src/borg/repository.py @@ -491,6 +491,14 @@ def open(self, path, exclusive, lock_wait=None, lock=True): self.close() 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): if self.lock: if self.io: From a7870ab5bd481815b815cd856111223ee53bcb1a Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Fri, 1 Jul 2022 00:15:13 +0200 Subject: [PATCH 2/2] only accept old repos for --other-repo (e.g. rcreate/transfer) we do not want to run the new borg code against old repos. if you want to e.g. check an old repo, use an old borg version. --- src/borg/archiver.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/borg/archiver.py b/src/borg/archiver.py index 816cc9e7e..d0ef9338b 100644 --- a/src/borg/archiver.py +++ b/src/borg/archiver.py @@ -191,6 +191,9 @@ def wrapper(self, args, **kwargs): args=args) with repository: + if repository.version not in (2, ): + raise Error("This borg version only accepts version 2 repos for -r/--repo. " + "You can use 'borg transfer' to copy archives from old to new repos.") if manifest or cache: kwargs['manifest'], kwargs['key'] = Manifest.load(repository, compatibility) if 'compression' in args: @@ -233,6 +236,8 @@ def wrapper(self, args, **kwargs): args=args) with repository: + if repository.version not in (1, 2, ): + raise Error("This borg version only accepts version 1 or 2 repos for --other-repo.") kwargs['other_repository'] = repository if manifest or key or cache: manifest_, key_ = Manifest.load(repository, compatibility)