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