selfprivacy-rest-api/selfprivacy_api/backup/backuppers/__init__.py

74 lines
2.0 KiB
Python
Raw Normal View History

from abc import ABC, abstractmethod
2023-02-13 13:16:35 +02:00
from typing import List
from selfprivacy_api.models.backup.snapshot import Snapshot
from selfprivacy_api.graphql.common_types.backup import BackupReason
class AbstractBackupper(ABC):
2023-07-20 18:24:26 +03:00
"""Abstract class for backuppers"""
# flake8: noqa: B027
2023-07-19 15:59:51 +03:00
def __init__(self) -> None:
pass
2023-03-14 02:39:15 +02:00
@abstractmethod
def is_initted(self) -> bool:
2023-07-20 18:24:26 +03:00
"""Returns true if the repository is initted"""
raise NotImplementedError
@abstractmethod
2023-07-19 15:59:51 +03:00
def set_creds(self, account: str, key: str, repo: str) -> None:
2023-07-20 18:24:26 +03:00
"""Set the credentials for the backupper"""
2023-03-14 02:39:15 +02:00
raise NotImplementedError
@abstractmethod
def start_backup(
self,
folders: List[str],
service_name: str,
reason: BackupReason = BackupReason.EXPLICIT,
) -> Snapshot:
2023-07-20 18:24:26 +03:00
"""Start a backup of the given folders"""
raise NotImplementedError
2023-02-13 13:16:35 +02:00
@abstractmethod
def get_snapshots(self) -> List[Snapshot]:
2023-02-13 13:16:35 +02:00
"""Get all snapshots from the repo"""
raise NotImplementedError
@abstractmethod
2023-07-19 15:59:51 +03:00
def init(self) -> None:
2023-07-20 18:24:26 +03:00
"""Initialize the repository"""
raise NotImplementedError
@abstractmethod
def erase_repo(self) -> None:
"""Completely empties the remote"""
raise NotImplementedError
@abstractmethod
def restore_from_backup(
self,
snapshot_id: str,
folders: List[str],
verify=True,
2023-07-19 15:59:51 +03:00
) -> None:
"""Restore a target folder using a snapshot"""
raise NotImplementedError
2023-02-22 20:48:08 +02:00
@abstractmethod
2023-06-23 12:40:10 +03:00
def restored_size(self, snapshot_id: str) -> int:
2023-07-20 18:24:26 +03:00
"""Get the size of the restored snapshot"""
2023-02-22 20:48:08 +02:00
raise NotImplementedError
2023-07-05 16:13:30 +03:00
@abstractmethod
2023-07-19 15:59:51 +03:00
def forget_snapshot(self, snapshot_id) -> None:
2023-07-20 18:24:26 +03:00
"""Forget a snapshot"""
2023-07-05 16:13:30 +03:00
raise NotImplementedError
@abstractmethod
def forget_snapshots(self, snapshot_ids: List[str]) -> None:
"""Maybe optimized deletion of a batch of snapshots, just cycling if unsupported"""
raise NotImplementedError