mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-11-25 21:41:27 +00:00
refactor(backups): make api accept a list of folders
This commit is contained in:
parent
d1e1039519
commit
f0aabec947
|
@ -194,11 +194,11 @@ class Backups:
|
|||
@staticmethod
|
||||
def back_up(service: Service):
|
||||
"""The top-level function to back up a service"""
|
||||
folder = service.get_folders()
|
||||
folders = service.get_folders()
|
||||
repo_name = service.get_id()
|
||||
|
||||
service.pre_backup()
|
||||
snapshot = Backups.provider().backuper.start_backup(folder, repo_name)
|
||||
snapshot = Backups.provider().backuper.start_backup(folders, repo_name)
|
||||
Backups._store_last_snapshot(repo_name, snapshot)
|
||||
|
||||
service.post_restore()
|
||||
|
@ -238,9 +238,9 @@ class Backups:
|
|||
@staticmethod
|
||||
def restore_service_from_snapshot(service: Service, snapshot_id: str):
|
||||
repo_name = service.get_id()
|
||||
folder = service.get_folders()
|
||||
folders = service.get_folders()
|
||||
|
||||
Backups.provider().backuper.restore_from_backup(repo_name, snapshot_id, folder)
|
||||
Backups.provider().backuper.restore_from_backup(repo_name, snapshot_id, folders)
|
||||
|
||||
@staticmethod
|
||||
def restore_snapshot(snapshot: Snapshot):
|
||||
|
|
|
@ -13,7 +13,7 @@ class AbstractBackuper(ABC):
|
|||
raise NotImplementedError
|
||||
|
||||
@abstractmethod
|
||||
def start_backup(self, folder: str, repo_name: str):
|
||||
def start_backup(self, folders: List[str], repo_name: str):
|
||||
raise NotImplementedError
|
||||
|
||||
@abstractmethod
|
||||
|
@ -26,7 +26,7 @@ class AbstractBackuper(ABC):
|
|||
raise NotImplementedError
|
||||
|
||||
@abstractmethod
|
||||
def restore_from_backup(self, repo_name: str, snapshot_id: str, folder: str):
|
||||
def restore_from_backup(self, repo_name: str, snapshot_id: str, folders: List[str]):
|
||||
"""Restore a target folder using a snapshot"""
|
||||
raise NotImplementedError
|
||||
|
||||
|
|
|
@ -57,15 +57,19 @@ class ResticBackuper(AbstractBackuper):
|
|||
command.extend(args)
|
||||
return command
|
||||
|
||||
def start_backup(self, folder: str, repo_name: str):
|
||||
def start_backup(self, folders: List[str], repo_name: str):
|
||||
"""
|
||||
Start backup with restic
|
||||
"""
|
||||
|
||||
# but maybe it is ok to accept a union of a string and an array of strings
|
||||
assert not isinstance(folders, str)
|
||||
|
||||
backup_command = self.restic_command(
|
||||
repo_name,
|
||||
"backup",
|
||||
"--json",
|
||||
folder,
|
||||
folders[0],
|
||||
)
|
||||
with subprocess.Popen(
|
||||
backup_command,
|
||||
|
@ -145,7 +149,7 @@ class ResticBackuper(AbstractBackuper):
|
|||
except ValueError as e:
|
||||
raise ValueError("cannot restore a snapshot: " + output) from e
|
||||
|
||||
def restore_from_backup(self, repo_name, snapshot_id, folder):
|
||||
def restore_from_backup(self, repo_name, snapshot_id, folders):
|
||||
"""
|
||||
Restore from backup with restic
|
||||
"""
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
"""Class representing Bitwarden service"""
|
||||
import base64
|
||||
import typing
|
||||
from typing import List
|
||||
|
||||
from selfprivacy_api.jobs import Job
|
||||
from selfprivacy_api.services.service import Service, ServiceDnsRecord, ServiceStatus
|
||||
|
@ -111,9 +112,8 @@ class DummyService(Service):
|
|||
return "sda1"
|
||||
|
||||
@classmethod
|
||||
def get_folders(cls) -> str:
|
||||
# for now only a single folder
|
||||
return cls.location
|
||||
def get_folders(cls) -> List[str]:
|
||||
return [cls.location]
|
||||
|
||||
@staticmethod
|
||||
def get_dns_records() -> typing.List[ServiceDnsRecord]:
|
||||
|
|
|
@ -143,10 +143,10 @@ def test_one_snapshot(backups, dummy_service):
|
|||
|
||||
|
||||
def test_backup_returns_snapshot(backups, dummy_service):
|
||||
service_folder = dummy_service.get_folders()
|
||||
service_folders = dummy_service.get_folders()
|
||||
provider = Backups.provider()
|
||||
name = dummy_service.get_id()
|
||||
snapshot = provider.backuper.start_backup(service_folder, name)
|
||||
snapshot = provider.backuper.start_backup(service_folders, name)
|
||||
|
||||
assert snapshot.id is not None
|
||||
assert snapshot.service_name == name
|
||||
|
@ -154,7 +154,7 @@ def test_backup_returns_snapshot(backups, dummy_service):
|
|||
|
||||
|
||||
def test_restore(backups, dummy_service):
|
||||
service_folder = dummy_service.get_folders()
|
||||
service_folder = dummy_service.get_folders()[0]
|
||||
file_to_nuke = listdir(service_folder)[0]
|
||||
assert file_to_nuke is not None
|
||||
path_to_nuke = path.join(service_folder, file_to_nuke)
|
||||
|
|
Loading…
Reference in a new issue