MCPcopy Create free account
hub / github.com/agent0ai/agent-zero / inspect_backup

Method inspect_backup

helpers/backup.py:432–465  ·  view source on GitHub ↗

Inspect backup archive and return metadata

(self, backup_file)

Source from the content-addressed store, hash-verified

430 raise Exception(f"Error creating backup: {str(e)}")
431
432 async def inspect_backup(self, backup_file) -> Dict[str, Any]:
433 """Inspect backup archive and return metadata"""
434
435 # Save uploaded file temporarily
436 temp_dir = tempfile.mkdtemp()
437 temp_file = os.path.join(temp_dir, "backup.zip")
438
439 try:
440 backup_file.save(temp_file)
441
442 with zipfile.ZipFile(temp_file, 'r') as zipf:
443 # Read metadata
444 if "metadata.json" not in zipf.namelist():
445 raise Exception("Invalid backup file: missing metadata.json")
446
447 metadata_content = zipf.read("metadata.json").decode('utf-8')
448 metadata = json.loads(metadata_content)
449
450 # Add file list from archive
451 files_in_archive = [name for name in zipf.namelist() if name != "metadata.json"]
452 metadata["files_in_archive"] = files_in_archive
453
454 return metadata
455
456 except zipfile.BadZipFile:
457 raise Exception("Invalid backup file: not a valid zip archive")
458 except json.JSONDecodeError:
459 raise Exception("Invalid backup file: corrupted metadata")
460 finally:
461 # Cleanup
462 if os.path.exists(temp_file):
463 os.remove(temp_file)
464 if os.path.exists(temp_dir):
465 os.rmdir(temp_dir)
466
467 async def preview_restore(
468 self,

Callers 1

processMethod · 0.95

Calls 5

joinMethod · 0.45
saveMethod · 0.45
decodeMethod · 0.45
readMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected