Aggiorna coda dopo ogni file copiato

This commit is contained in:
2026-07-02 09:42:26 +02:00
parent e5a76992d4
commit 2d837008be
3 changed files with 121 additions and 12 deletions

View File

@@ -52,19 +52,24 @@ def run_backup(config: AppConfig, logger: logging.Logger) -> BackupResult:
skipped_count=len(skipped) + len(unstable),
)
copy_result = _run_copy_engine(config, stable, logger)
copy_result = _run_copy_engine(config, stable, logger, registry)
if not copy_result.success:
return BackupResult(
False,
copy_result.message,
copied_count=copy_result.copied_count,
skipped_count=len(skipped) + len(unstable),
error_code=copy_result.error_code,
)
registry.mark_status([event.path for event in stable], "copied")
message = f"Backup completato: {len(stable)} file copiati"
message = f"Backup completato: {copy_result.copied_count} file copiati"
logger.info(message)
return BackupResult(True, message, copied_count=len(stable), skipped_count=len(skipped) + len(unstable))
return BackupResult(
True,
message,
copied_count=copy_result.copied_count,
skipped_count=len(skipped) + len(unstable),
)
def shutdown_after_backup(config: AppConfig, logger: logging.Logger) -> bool:
@@ -144,25 +149,40 @@ def _build_rsync_command(config: AppConfig, events: list[ChangeEvent]) -> list[s
]
def _run_copy_engine(config: AppConfig, events: list[ChangeEvent], logger: logging.Logger) -> BackupResult:
def _run_copy_engine(
config: AppConfig,
events: list[ChangeEvent],
logger: logging.Logger,
registry: ChangeRegistry,
) -> BackupResult:
if config.backup.engine == "robocopy":
return _run_robocopy(config, events, logger)
return _run_robocopy(config, events, logger, registry)
if config.backup.engine == "rsync":
return _run_rsync(config, events, logger)
result = _run_rsync(config, events, logger)
if result.success:
registry.mark_status([event.path for event in events], "copied")
return BackupResult(True, result.message, copied_count=len(events))
return result
message = f"Motore backup non supportato: {config.backup.engine}"
logger.error(message)
return BackupResult(False, message, error_code="backup_engine_unsupported")
def _run_robocopy(config: AppConfig, events: list[ChangeEvent], logger: logging.Logger) -> BackupResult:
def _run_robocopy(
config: AppConfig,
events: list[ChangeEvent],
logger: logging.Logger,
registry: ChangeRegistry,
) -> BackupResult:
if not config.backup.remote_destinations:
message = "Nessuna destinazione robocopy configurata"
logger.error(message)
return BackupResult(False, message, error_code="backup_destination_missing")
copied_files = 0
copied_commands = 0
for destination_root in config.backup.remote_destinations:
for event in events:
for event in events:
for destination_root in config.backup.remote_destinations:
command = _build_robocopy_command(config, event, destination_root)
logger.info("Running robocopy command: %s", _redact_command(command))
try:
@@ -182,8 +202,19 @@ def _run_robocopy(config: AppConfig, events: list[ChangeEvent], logger: logging.
logger.error(message)
return BackupResult(False, message, error_code="robocopy_failed")
copied_commands += 1
registry.mark_status([event.path], "copied")
copied_files += 1
logger.info(
"Marked copied after successful robocopy to %s destination(s): %s",
len(config.backup.remote_destinations),
event.path,
)
return BackupResult(True, f"Robocopy completato: {copied_commands} copie")
return BackupResult(
True,
f"Robocopy completato: {copied_files} file, {copied_commands} copie",
copied_count=copied_files,
)
def _run_rsync(config: AppConfig, events: list[ChangeEvent], logger: logging.Logger) -> BackupResult: