Imposta backup robocopy su share Windows

This commit is contained in:
2026-07-01 12:37:48 +02:00
parent d5bff3d8e4
commit 0970e0af3d
12 changed files with 304 additions and 44 deletions

View File

@@ -2,7 +2,12 @@ from __future__ import annotations
from pathlib import Path
from bakrest.backup import _build_rsync_command, _split_existing_files
from bakrest.backup import (
_build_robocopy_command,
_build_rsync_command,
_robocopy_destination_dir,
_split_existing_files,
)
from bakrest.config import parse_config
from bakrest.registry import ChangeEvent
@@ -50,3 +55,43 @@ def test_build_rsync_command_uses_files_from(tmp_path: Path) -> None:
assert "--relative" in command
assert any(part.startswith("--files-from=") for part in command)
assert command[-1] == "user@host:/backup/"
def test_build_robocopy_command_preserves_path_under_include_root(tmp_path: Path) -> None:
source = tmp_path / "Lavori"
nested = source / "Cliente" / "Grafica"
nested.mkdir(parents=True)
image = nested / "image.psd"
image.write_text("ok", encoding="utf-8")
config = parse_config(
{
"watch": {
"include_dirs": [str(source)],
"include_extensions": [".psd"],
"exclude_dirs": [],
"exclude_patterns": [],
},
"backup": {
"engine": "robocopy",
"robocopy_path": "robocopy",
"remote_destinations": ["\\\\server\\Backup1", "\\\\server\\Backup2"],
"server_check": {"type": "tcp", "port": 445, "interval_seconds": 300, "timeout_seconds": 1},
},
},
tmp_path / "config.toml",
)
destination = _robocopy_destination_dir(config, image, Path("\\\\server\\Backup1"))
command = _build_robocopy_command(
config,
ChangeEvent(path=str(image), event_type="modified"),
"\\\\server\\Backup1",
)
assert destination == Path("\\\\server\\Backup1") / "Lavori" / "Cliente" / "Grafica"
assert command[0] == "robocopy"
assert command[1] == str(nested)
assert command[2] == str(destination)
assert command[3] == "image.psd"
assert "/MIR" not in command
assert "/PURGE" not in command

View File

@@ -7,4 +7,6 @@ def test_nogui_exit_codes_are_specific() -> None:
assert _exit_code_for_error("server_unreachable") == 20
assert _exit_code_for_error("rsync_start_failed") == 30
assert _exit_code_for_error("rsync_failed") == 31
assert _exit_code_for_error("robocopy_start_failed") == 30
assert _exit_code_for_error("robocopy_failed") == 31
assert _exit_code_for_error(None) == 1

View File

@@ -22,6 +22,35 @@ def test_parse_config_normalizes_extensions(tmp_path: Path) -> None:
assert config.watch.include_extensions == frozenset({".jpg", ".png"})
def test_parse_config_reads_multiple_remote_destinations(tmp_path: Path) -> None:
config = parse_config(
{
"backup": {
"engine": "robocopy",
"remote_destinations": ["\\\\server\\Backup1", "\\\\server\\Backup2"],
}
},
tmp_path / "config.toml",
)
assert config.backup.engine == "robocopy"
assert config.backup.remote_destinations == ("\\\\server\\Backup1", "\\\\server\\Backup2")
def test_parse_config_ignores_legacy_rsync_destination_for_robocopy(tmp_path: Path) -> None:
config = parse_config(
{
"backup": {
"engine": "robocopy",
"remote_destination": "utente@backup-server:/backup/bak-rest/",
}
},
tmp_path / "config.toml",
)
assert config.backup.remote_destinations == ()
def test_filter_accepts_included_extension(tmp_path: Path) -> None:
config = parse_config(
{