mirror of
https://github.com/aljazceru/plugins.git
synced 2025-12-19 22:24:19 +01:00
backup: Implement network backup
This commit is contained in:
committed by
Christian Decker
parent
4f4e30bb49
commit
804a9bb290
33
backup/backends.py
Normal file
33
backup/backends.py
Normal file
@@ -0,0 +1,33 @@
|
||||
'''Create a backend instance based on URI scheme dispatch.'''
|
||||
from typing import Type
|
||||
from urllib.parse import urlparse
|
||||
|
||||
from backend import Backend
|
||||
from socketbackend import SocketBackend
|
||||
from filebackend import FileBackend
|
||||
|
||||
|
||||
def resolve_backend_class(backend_url):
|
||||
|
||||
backend_map: Mapping[str, Type[Backend]] = {
|
||||
'file': FileBackend,
|
||||
'socket': SocketBackend,
|
||||
}
|
||||
p = urlparse(backend_url)
|
||||
backend_cl = backend_map.get(p.scheme, None)
|
||||
return backend_cl
|
||||
|
||||
|
||||
def get_backend(destination, create=False, require_init=False):
|
||||
backend_cl = resolve_backend_class(destination)
|
||||
if backend_cl is None:
|
||||
raise ValueError("No backend implementation found for {destination}".format(
|
||||
destination=destination,
|
||||
))
|
||||
backend = backend_cl(destination, create=create)
|
||||
initialized = backend.initialize()
|
||||
if require_init and not initialized:
|
||||
kill("Could not initialize the backup {}, please use 'backup-cli' to initialize the backup first.".format(destination))
|
||||
assert(backend.version is not None)
|
||||
assert(backend.prev_version is not None)
|
||||
return backend
|
||||
Reference in New Issue
Block a user