40 lines
1.0 KiB
Python
40 lines
1.0 KiB
Python
#!/usr/bin/env python3
|
|
"""Verify a backup and restore it into a clean target directory."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import json
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
if str(ROOT) not in sys.path:
|
|
sys.path.insert(0, str(ROOT))
|
|
|
|
from packages.hub_operations.backup import BackupManager # noqa: E402
|
|
|
|
|
|
def main() -> int:
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("--backup-root", type=Path, required=True)
|
|
parser.add_argument("--archive", type=Path, required=True)
|
|
parser.add_argument("--target-root", type=Path, required=True)
|
|
args = parser.parse_args()
|
|
artifact = BackupManager(args.backup_root).restore_clean(args.archive, args.target_root)
|
|
print(
|
|
json.dumps(
|
|
{
|
|
"restored": str(args.target_root),
|
|
"sha256": artifact.sha256,
|
|
"entries": artifact.entries,
|
|
},
|
|
sort_keys=True,
|
|
)
|
|
)
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|