refactor(backups): move syncing (non-restic) into backup utils

This commit is contained in:
Houkime 2023-07-03 13:28:23 +00:00 committed by Inex Code
parent 7ad5f91be1
commit 9a28c0ebcb
3 changed files with 16 additions and 15 deletions

View file

@ -84,18 +84,6 @@ class ResticBackupper(AbstractBackupper):
result.append(item)
return result
@staticmethod
def sync(src_path: str, dest_path: str):
"""a wrapper around rclone sync"""
if not exists(src_path):
raise ValueError("source dir for rclone sync must exist")
rclone_command = ["rclone", "sync", "-P", src_path, dest_path]
for raw_message in output_yielder(rclone_command):
if "ERROR" in raw_message:
raise ValueError(raw_message)
def start_backup(self, folders: List[str], tag: str):
"""
Start backup with restic

View file

@ -1,4 +1,5 @@
import subprocess
from os.path import exists
def output_yielder(command):
@ -12,3 +13,15 @@ def output_yielder(command):
for line in iter(handle.stdout.readline, ""):
if "NOTICE:" not in line:
yield line
def sync(src_path: str, dest_path: str):
"""a wrapper around rclone sync"""
if not exists(src_path):
raise ValueError("source dir for rclone sync must exist")
rclone_command = ["rclone", "sync", "-P", src_path, dest_path]
for raw_message in output_yielder(rclone_command):
if "ERROR" in raw_message:
raise ValueError(raw_message)

View file

@ -18,8 +18,8 @@ from selfprivacy_api.backup import Backups
import selfprivacy_api.backup.providers as providers
from selfprivacy_api.backup.providers import AbstractBackupProvider
from selfprivacy_api.backup.providers.backblaze import Backblaze
from selfprivacy_api.backup.util import sync
from selfprivacy_api.backup.backuppers.restic_backupper import ResticBackupper
from selfprivacy_api.backup.tasks import start_backup, restore_snapshot
from selfprivacy_api.backup.storage import Storage
@ -537,7 +537,7 @@ def test_sync(dummy_service):
old_files_dst = listdir(dst)
assert old_files_src != old_files_dst
ResticBackupper.sync(src, dst)
sync(src, dst)
new_files_src = listdir(src)
new_files_dst = listdir(dst)
assert new_files_src == old_files_src
@ -549,4 +549,4 @@ def test_sync_nonexistent_src(dummy_service):
dst = dummy_service.get_folders()[1]
with pytest.raises(ValueError):
ResticBackupper.sync(src, dst)
sync(src, dst)