mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-11-22 12:11:26 +00:00
refactor(backups): privatize assert_restorable and restore_snapshot_from_id
This commit is contained in:
parent
2f2c4f14af
commit
b9be0be6a2
|
@ -209,31 +209,6 @@ class Backups:
|
|||
|
||||
### Restoring
|
||||
|
||||
# to be deprecated/internalized in favor of restore_snapshot()
|
||||
@staticmethod
|
||||
def restore_service_from_snapshot(service: Service, snapshot_id: str):
|
||||
folders = service.get_folders()
|
||||
|
||||
Backups.provider().backupper.restore_from_backup(
|
||||
snapshot_id,
|
||||
folders,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def assert_restorable(snapshot: Snapshot):
|
||||
service = get_service_by_id(snapshot.service_name)
|
||||
if service is None:
|
||||
raise ValueError(
|
||||
f"snapshot has a nonexistent service: {snapshot.service_name}"
|
||||
)
|
||||
|
||||
needed_space = Backups.service_snapshot_size(snapshot.id)
|
||||
available_space = Backups.space_usable_for_service(service)
|
||||
if needed_space > available_space:
|
||||
raise ValueError(
|
||||
f"we only have {available_space} bytes "
|
||||
f"but snapshot needs {needed_space}"
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def restore_snapshot(snapshot: Snapshot):
|
||||
|
@ -253,8 +228,8 @@ class Backups:
|
|||
status=JobStatus.RUNNING,
|
||||
)
|
||||
try:
|
||||
Backups.assert_restorable(snapshot)
|
||||
Backups.restore_service_from_snapshot(
|
||||
Backups._assert_restorable(snapshot)
|
||||
Backups._restore_service_from_snapshot(
|
||||
service,
|
||||
snapshot.id,
|
||||
)
|
||||
|
@ -271,6 +246,31 @@ class Backups:
|
|||
status=JobStatus.FINISHED,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def _assert_restorable(snapshot: Snapshot):
|
||||
service = get_service_by_id(snapshot.service_name)
|
||||
if service is None:
|
||||
raise ValueError(
|
||||
f"snapshot has a nonexistent service: {snapshot.service_name}"
|
||||
)
|
||||
|
||||
needed_space = Backups.service_snapshot_size(snapshot.id)
|
||||
available_space = Backups.space_usable_for_service(service)
|
||||
if needed_space > available_space:
|
||||
raise ValueError(
|
||||
f"we only have {available_space} bytes "
|
||||
f"but snapshot needs {needed_space}"
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def _restore_service_from_snapshot(service: Service, snapshot_id: str):
|
||||
folders = service.get_folders()
|
||||
|
||||
Backups.provider().backupper.restore_from_backup(
|
||||
snapshot_id,
|
||||
folders,
|
||||
)
|
||||
|
||||
### Snapshots
|
||||
|
||||
@staticmethod
|
||||
|
|
|
@ -222,7 +222,7 @@ def test_restore(backups, dummy_service):
|
|||
remove(p)
|
||||
assert not path.exists(p)
|
||||
|
||||
Backups.restore_service_from_snapshot(dummy_service, snap.id)
|
||||
Backups._restore_service_from_snapshot(dummy_service, snap.id)
|
||||
for p, content in zip(paths_to_nuke, contents):
|
||||
assert path.exists(p)
|
||||
with open(p, "r") as file:
|
||||
|
|
Loading…
Reference in a new issue