Restore from a backup archive. WARNING: This will overwrite the database!
(backup_file: Path)
| 281 | |
| 282 | |
| 283 | def restore_backup(backup_file: Path) -> None: |
| 284 | """ |
| 285 | Restore from a backup archive. |
| 286 | WARNING: This will overwrite the database! |
| 287 | """ |
| 288 | if not backup_file.exists(): |
| 289 | raise FileNotFoundError(f"Backup file not found: {backup_file}") |
| 290 | |
| 291 | logger.info(f"Restoring from backup: {backup_file}") |
| 292 | |
| 293 | with tempfile.TemporaryDirectory(prefix="dispatcharr-restore-") as temp_dir: |
| 294 | temp_path = Path(temp_dir) |
| 295 | |
| 296 | # Extract backup |
| 297 | logger.debug("Extracting backup archive...") |
| 298 | with ZipFile(backup_file, "r") as zip_file: |
| 299 | zip_file.extractall(temp_path) |
| 300 | |
| 301 | # Read metadata |
| 302 | metadata_file = temp_path / "metadata.json" |
| 303 | if not metadata_file.exists(): |
| 304 | raise ValueError("Invalid backup: missing metadata.json") |
| 305 | |
| 306 | with open(metadata_file) as f: |
| 307 | metadata = json.load(f) |
| 308 | |
| 309 | # Restore database |
| 310 | _restore_database(temp_path, metadata) |
| 311 | |
| 312 | logger.info("Restore completed successfully") |
| 313 | |
| 314 | |
| 315 | def _restore_database(temp_path: Path, metadata: dict) -> None: |
nothing calls this directly
no test coverage detected