mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-11-18 08:29:14 +00:00
refactor(backups): move syncing (non-restic) into backup utils
This commit is contained in:
parent
7ad5f91be1
commit
9a28c0ebcb
|
@ -84,18 +84,6 @@ class ResticBackupper(AbstractBackupper):
|
||||||
result.append(item)
|
result.append(item)
|
||||||
return result
|
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):
|
def start_backup(self, folders: List[str], tag: str):
|
||||||
"""
|
"""
|
||||||
Start backup with restic
|
Start backup with restic
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import subprocess
|
import subprocess
|
||||||
|
from os.path import exists
|
||||||
|
|
||||||
|
|
||||||
def output_yielder(command):
|
def output_yielder(command):
|
||||||
|
@ -12,3 +13,15 @@ def output_yielder(command):
|
||||||
for line in iter(handle.stdout.readline, ""):
|
for line in iter(handle.stdout.readline, ""):
|
||||||
if "NOTICE:" not in line:
|
if "NOTICE:" not in line:
|
||||||
yield 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)
|
||||||
|
|
|
@ -18,8 +18,8 @@ from selfprivacy_api.backup import Backups
|
||||||
import selfprivacy_api.backup.providers as providers
|
import selfprivacy_api.backup.providers as providers
|
||||||
from selfprivacy_api.backup.providers import AbstractBackupProvider
|
from selfprivacy_api.backup.providers import AbstractBackupProvider
|
||||||
from selfprivacy_api.backup.providers.backblaze import Backblaze
|
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.tasks import start_backup, restore_snapshot
|
||||||
from selfprivacy_api.backup.storage import Storage
|
from selfprivacy_api.backup.storage import Storage
|
||||||
|
@ -537,7 +537,7 @@ def test_sync(dummy_service):
|
||||||
old_files_dst = listdir(dst)
|
old_files_dst = listdir(dst)
|
||||||
assert old_files_src != old_files_dst
|
assert old_files_src != old_files_dst
|
||||||
|
|
||||||
ResticBackupper.sync(src, dst)
|
sync(src, dst)
|
||||||
new_files_src = listdir(src)
|
new_files_src = listdir(src)
|
||||||
new_files_dst = listdir(dst)
|
new_files_dst = listdir(dst)
|
||||||
assert new_files_src == old_files_src
|
assert new_files_src == old_files_src
|
||||||
|
@ -549,4 +549,4 @@ def test_sync_nonexistent_src(dummy_service):
|
||||||
dst = dummy_service.get_folders()[1]
|
dst = dummy_service.get_folders()[1]
|
||||||
|
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
ResticBackupper.sync(src, dst)
|
sync(src, dst)
|
||||||
|
|
Loading…
Reference in a new issue