Imposta backup robocopy su share Windows
This commit is contained in:
@@ -22,9 +22,12 @@ class ServerCheckConfig:
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class BackupConfig:
|
||||
engine: str
|
||||
server_host: str
|
||||
remote_destination: str
|
||||
remote_destinations: tuple[str, ...]
|
||||
rsync_path: str
|
||||
robocopy_path: str
|
||||
shutdown_on_success: bool
|
||||
shutdown_command: str
|
||||
server_check: ServerCheckConfig
|
||||
@@ -130,9 +133,12 @@ def parse_config(data: dict[str, Any], path: Path) -> AppConfig:
|
||||
exclude_patterns=tuple(watch.get("exclude_patterns", [])),
|
||||
),
|
||||
backup=BackupConfig(
|
||||
engine=str(backup.get("engine", "robocopy")).lower(),
|
||||
server_host=str(backup.get("server_host", "backup-server")),
|
||||
remote_destination=str(backup.get("remote_destination", "")),
|
||||
remote_destinations=_remote_destinations(backup),
|
||||
rsync_path=str(backup.get("rsync_path", "rsync")),
|
||||
robocopy_path=str(backup.get("robocopy_path", "robocopy")),
|
||||
shutdown_on_success=bool(backup.get("shutdown_on_success", True)),
|
||||
shutdown_command=str(backup.get("shutdown_command", "shutdown /s /t 0")),
|
||||
server_check=ServerCheckConfig(
|
||||
@@ -165,3 +171,23 @@ def _normalize_exclude_dir(value: str) -> Path | str:
|
||||
if "%" in value or not expanded.is_absolute():
|
||||
return value.lower()
|
||||
return expanded
|
||||
|
||||
|
||||
def _remote_destinations(backup: dict[str, Any]) -> tuple[str, ...]:
|
||||
destinations = backup.get("remote_destinations")
|
||||
if isinstance(destinations, list):
|
||||
return tuple(str(item).strip() for item in destinations if str(item).strip())
|
||||
|
||||
destination = str(backup.get("remote_destination", "")).strip()
|
||||
engine = str(backup.get("engine", "robocopy")).lower()
|
||||
if engine == "robocopy" and not _is_windows_destination(destination):
|
||||
return ()
|
||||
return (destination,) if destination else ()
|
||||
|
||||
|
||||
def _is_windows_destination(destination: str) -> bool:
|
||||
if destination.startswith("\\\\"):
|
||||
return True
|
||||
if len(destination) >= 3 and destination[1:3] == ":\\":
|
||||
return True
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user