Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Just download files from a single node in backup #260

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 19 additions & 15 deletions astacus/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

"""

from argparse import ArgumentParser
from astacus.common import ipc
from astacus.common.rohmustorage import RohmuConfig, RohmuStorage
from pathlib import Path
Expand All @@ -21,7 +22,7 @@
logger = logging.getLogger(__name__)


def create_manifest_parsers(parser, subparsers):
def create_manifest_parsers(parser: ArgumentParser, subparsers):
p_manifest = subparsers.add_parser("manifest", help="Examine Astacus backup manifests")
p_manifest.add_argument("-c", "--config", type=str, required=True, help="Astacus server configuration file to use")
p_manifest.add_argument("-s", "--storage", type=str, help="Storage to use")
Expand Down Expand Up @@ -62,27 +63,30 @@ def create_download_files_parser(subparsers):
)
p_download_files.add_argument("destination", type=str, help="Destination directory to download files to")
p_download_files.add_argument("--prefix", type=str, help="Prefix to filter files", required=True)
p_download_files.add_argument("--node", type=int, help="Node index to download files from", 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 not snapshot_file.relative_path.startswith(args.prefix):
continue

path = destination / snapshot_file.relative_path
path.parent.mkdir(parents=True, exist_ok=True)
logger.info("Downloading %s to %s", snapshot_file.relative_path, path)
if snapshot_file.hexdigest:
rohmu_storage.download_hexdigest_to_path(snapshot_file.hexdigest, path)
else:
assert snapshot_file.content_b64 is not None
path.write_bytes(base64.b64decode(snapshot_file.content_b64))
if args.node >= len(manifest.upload_results):
raise ValueError(f"Node {args.node} not found in manifest")
snapshot_result = manifest.snapshot_results[args.node]
assert snapshot_result.state
for snapshot_file in snapshot_result.state.files:
if not snapshot_file.relative_path.startswith(args.prefix):
continue

path = destination / snapshot_file.relative_path
path.parent.mkdir(parents=True, exist_ok=True)
logger.info("Downloading %s to %s", snapshot_file.relative_path, path)
if snapshot_file.hexdigest:
rohmu_storage.download_hexdigest_to_path(snapshot_file.hexdigest, path)
else:
assert snapshot_file.content_b64 is not None
path.write_bytes(base64.b64decode(snapshot_file.content_b64))


def _run_list(args):
Expand Down
Loading