MCPcopy Create free account
hub / github.com/Dispatcharr/Dispatcharr / restore_backup

Function restore_backup

apps/backups/services.py:283–312  ·  view source on GitHub ↗

Restore from a backup archive. WARNING: This will overwrite the database!

(backup_file: Path)

Source from the content-addressed store, hash-verified

281
282
283def 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
315def _restore_database(temp_path: Path, metadata: dict) -> None:

Callers

nothing calls this directly

Calls 2

_restore_databaseFunction · 0.85
existsMethod · 0.45

Tested by

no test coverage detected