backend: Use th backup URL in backup-cli and add snapshot type to FileBackend

This commit is contained in:
Christian Decker
2020-04-04 16:20:46 +02:00
parent c58e675877
commit 4c146bf2a4
3 changed files with 31 additions and 31 deletions

View File

@@ -132,10 +132,11 @@ class FileBackend(Backend):
with open(self.url.path, 'ab') as f:
f.seek(self.offsets[0])
f.write(length)
f.write(typ)
f.write(payload)
self.prev_version, self.offsets[1] = self.version, self.offsets[0]
self.version = entry.version
self.offsets[0] += 4 + len(payload)
self.offsets[0] += 5 + len(payload)
self.write_metadata()
return True
@@ -163,6 +164,15 @@ def resolve_backend_class(backend_url):
return backend_cl
def get_backend(destination):
backend_cl = resolve_backend_class(destination)
if backend_cl is None:
raise ValueError("No backend implementation found for {destination}".format(
destination=destination,
))
return backend_cl(destination)
def abort(reason: str) -> None:
plugin.log(reason)
plugin.rpc.stop()
@@ -246,12 +256,7 @@ def on_init(options: Mapping[str, str], plugin: Plugin, **kwargs):
if not plugin.db_path.startswith('sqlite3'):
abort("The backup plugin only works with the sqlite3 database.")
# Let's initialize the backed. First we need to figure out which backend to use.
backend_cl = resolve_backend_class(destination)
if backend_cl is None:
abort("Could not find a backend for scheme {p.scheme}".format(p=p))
plugin.backend = backend_cl(destination)
plugin.backend = get_backend(destination)
if not plugin.backend.initialize():
abort("Could not initialize the backup {}, please use 'backup-cli' to initialize the backup first.".format(destination))