add a script for unpacking snapshot files

Summary:
Add a script for unpacking saved snapshot files.

This unpacks the tarball and then fixes up absolute paths inside the snapshot
so it will work at the unpacked location.  It also emits a small helper script
to make it easier to invoke eden for the snapshot.

Reviewed By: wez

Differential Revision: D12927842

fbshipit-source-id: f46c07a79894877842f2a78aa0924fd66e4c8969
This commit is contained in:
Adam Simpkins 2018-11-07 17:00:41 -08:00 committed by Facebook Github Bot
parent d2b8fabdc3
commit 7c90dd8962
2 changed files with 67 additions and 1 deletions

View File

@ -493,7 +493,7 @@ def unpack_into(snapshot_path: Path, output_path: Path) -> BaseSnapshot:
"""
# GNU tar is smart enough to automatically figure out the correct
# decompression method.
untar_cmd = ["tar", "-xf", str(snapshot_path)]
untar_cmd = ["tar", "-xf", str(snapshot_path.absolute())]
subprocess.check_call(untar_cmd, cwd=output_path)
data_dir = output_path / "data"

View File

@ -0,0 +1,66 @@
#!/usr/bin/env python3
#
# Copyright (c) 2016-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree. An additional grant
# of patent rights can be found in the PATENTS file in the same directory.
import argparse
import os
from pathlib import Path
from . import snapshot as snapshot_mod
RUN_EDEN_SCRIPT = """\
#!/bin/bash
# Find the Eden binary to use.
DEV_EDEN="buck-out/gen/eden/cli/eden.par"
if [[ -n "$EDEN" ]]; then
# $EDEN is defined in the environment, so use that
:
elif [[ -x "$DEV_EDEN" ]]; then
# We appear to be running from an fbcode directory with a built
# version of eden in buck-out. Use it.
EDEN="$DEV_EDEN"
else
# Find eden from $PATH
EDEN="eden"
fi
SNAPSHOT_PATH={snapshot_path}
exec "$EDEN" \\
--etc-eden-dir "$SNAPSHOT_PATH/transient/etc_eden" \\
--config-dir "$SNAPSHOT_PATH/data/eden" \\
"$@"
"""
def main() -> None:
ap = argparse.ArgumentParser()
ap.add_argument("-o", "--output", required=True, help="The output directory path.")
ap.add_argument(
"--start", action="store_true", default=False, help="Also start EdenFS."
)
ap.add_argument("snapshot", help="The path of the snapshot file to unpack.")
args = ap.parse_args()
output_dir = Path(args.output)
input_path = Path(args.snapshot)
output_dir.mkdir()
snapshot_mod.unpack_into(input_path, output_dir)
# Write a small helper script that can be used to more easily invoke Eden in this
# repository.
run_eden_path = output_dir / "run_eden"
with run_eden_path.open("w") as f:
f.write(RUN_EDEN_SCRIPT.format(snapshot_path=output_dir))
os.fchmod(f.fileno(), 0o755)
if __name__ == "__main__":
main()