Skip to content

Commit

Permalink
Add tool for downloading files from a backup.
Browse files Browse the repository at this point in the history
  • Loading branch information
joelynch committed Nov 13, 2024
1 parent 074c8fa commit a415e37
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions astacus/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from astacus.common import ipc
from astacus.common.rohmustorage import RohmuConfig, RohmuStorage
from pathlib import Path

import json
import msgspec
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit a415e37

Please sign in to comment.