synchroniser : add backup to sync_files
Adds the option to enable backup when synchronising. This is done in sync_files by passing the appropriate arguments to sync. For this we need to add an argument to sync_files as the backup configuration options are needed. The configuration options are imported from unisync.config.BackupConfig. Also import typing.cast to be able to narrow down a type.
This commit is contained in:
@@ -14,8 +14,10 @@ import time
|
||||
import logging
|
||||
|
||||
from pathlib import Path
|
||||
from typing import cast
|
||||
|
||||
from unisync.errors import RemoteMountedError, InvalidMountError
|
||||
from unisync.config import BackupConfig
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -117,7 +119,9 @@ class Synchroniser:
|
||||
close = subprocess.Popen(command)
|
||||
return close.wait()
|
||||
|
||||
def sync_files(self, paths:list, force:bool=False) -> int:
|
||||
def sync_files(self, paths:list, force:bool=False,
|
||||
backup:BackupConfig | None = None
|
||||
) -> int:
|
||||
"""Synchronises the files.
|
||||
|
||||
Args:
|
||||
@@ -127,11 +131,35 @@ class Synchroniser:
|
||||
Returns:
|
||||
The return code of sync.
|
||||
"""
|
||||
other = list()
|
||||
if(backup != None and backup.enabled):
|
||||
backup = cast(BackupConfig, backup)
|
||||
|
||||
other.append("-backup")
|
||||
if(backup.selection != ""):
|
||||
other.append(backup.selection)
|
||||
else:
|
||||
other.append("Name *")
|
||||
|
||||
other.append([
|
||||
"-backuploc",
|
||||
backup.location,
|
||||
"-maxbackups",
|
||||
backup.max_backups,
|
||||
"-backupsuffix",
|
||||
backup.backupsuffix,
|
||||
"-backupprefix",
|
||||
backup.backupprefix,
|
||||
"-ignore",
|
||||
backup.backupprefix
|
||||
])
|
||||
|
||||
return self.sync(
|
||||
f"ssh://{self.remote_user}@{self.remote_ip}/{self.remote_dir}/.data",
|
||||
self.local,
|
||||
paths=paths,
|
||||
force=force
|
||||
force=force,
|
||||
other=other
|
||||
)
|
||||
|
||||
def sync_links(self, ignore:list) -> int:
|
||||
|
||||
Reference in New Issue
Block a user