diff --git a/astacus/manifest.py b/astacus/manifest.py index 53bce957..9a5a72b5 100644 --- a/astacus/manifest.py +++ b/astacus/manifest.py @@ -8,6 +8,7 @@ from astacus.common import ipc from astacus.common.rohmustorage import RohmuConfig, RohmuStorage +from pathlib import Path import json import msgspec @@ -48,6 +49,31 @@ def create_dump_parser(subparsers): p_dump.set_defaults(func=_run_dump) +def create_download_files_parser(subparsers): + p_download_files = subparsers.add_parser("download-from", help="Download files from a backup manifest") + p_download_files.add_argument( + "manifest", type=str, help="Manifest object name (can be obtained by running manifest list)", required=True + ) + p_download_files.add_argument("destination", type=str, help="Destination directory to download files to", required=True) + p_download_files.add_argument("--prefix", type=str, help="Prefix to filter files", required=True) + p_download_files.set_defaults(func=_run_download_files) + + +def _run_download_files(args): + rohmu_storage = _create_rohmu_storage(args.config, args.storage) + manifest = rohmu_storage.download_json(args.manifest, ipc.BackupManifest) + destination = Path(args.destination) + for snapshot_result in manifest.snapshot_results: + assert snapshot_result.state + for snapshot_file in snapshot_result.state.files: + if args.prefix and not snapshot_file.relative_path.startswith(args.prefix): + continue + + path = destination / snapshot_file.relative_path + path.parent.mkdir(parents=True, exist_ok=True) + rohmu_storage.download_hexdigest_to_path(snapshot_file.hexdigest, path) + + def _run_list(args): rohmu_storage = _create_rohmu_storage(args.config, args.storage) json_names = rohmu_storage.list_jsons()