Files
2026-07-17 12:57:18 +03:00

49 lines
1.4 KiB
Python

"""Restore project files from OTA backup directory."""
from __future__ import annotations
import logging
import os
import shutil
from typing import Optional
logger = logging.getLogger(__name__)
def restore_from_backup(base_dir: str, backup_path: Optional[str]) -> bool:
if not backup_path or not os.path.isdir(backup_path):
logger.error("Backup path missing or not a directory: %s", backup_path)
return False
try:
from update import AutoUpdater
au = AutoUpdater.__new__(AutoUpdater)
au.base_dir = base_dir
au.config_file = os.path.join(base_dir, "data", "config.json")
au.protected_files = [
"data/recipes.db",
"data/recipes.db-shm",
"data/recipes.db-wal",
"data/reports.db",
"data/reports.db-shm",
"data/reports.db-wal",
"data/update_state.json",
"data/.pending_restart.json",
"credentials.json",
"calibration_factor.json",
"weight_0.json",
"gitea_secrets.json",
]
au.protected_folders = [
"__pycache__",
".git",
"backups",
"temp_updates",
".secret",
]
au._restore_from_backup(backup_path)
return True
except Exception as exc:
logger.error("Rollback failed: %s", exc, exc_info=True)
return False