[IMP] cli restoredb: manage filestore in subfolder
This commit is contained in:
parent
a00ee58b62
commit
7d1183b140
|
|
@ -0,0 +1 @@
|
||||||
|
Handles the case where the filestore data provided in the source is in a "filestore" subfolder
|
||||||
|
|
@ -59,6 +59,15 @@ def restoredb(
|
||||||
"database-path should be inside the project path to allow "
|
"database-path should be inside the project path to allow "
|
||||||
"postgresql to read to it."
|
"postgresql to read to it."
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Check db path exists
|
||||||
|
if not database_path.exists():
|
||||||
|
ctx.fail(f"Database path {database_path} does not exist.")
|
||||||
|
|
||||||
|
# Check filestore path exists
|
||||||
|
if not filestore_path.exists():
|
||||||
|
ctx.fail(f"Filestore path {filestore_path} does not exist.")
|
||||||
|
|
||||||
# Restore the database
|
# Restore the database
|
||||||
output = execute_pg_restore(
|
output = execute_pg_restore(
|
||||||
ctx,
|
ctx,
|
||||||
|
|
|
||||||
|
|
@ -173,3 +173,12 @@ def restore_filestore(
|
||||||
else: # works for "t" and "tgz"
|
else: # works for "t" and "tgz"
|
||||||
tar = tarfile.open(src_path)
|
tar = tarfile.open(src_path)
|
||||||
tar.extractall(path=filestore_path)
|
tar.extractall(path=filestore_path)
|
||||||
|
|
||||||
|
# If a filestore/filestore/database/filestore directory exists,
|
||||||
|
# it means that the filestore was in a "filestore" subdirectory
|
||||||
|
# and we need to move this content to the parent directory.
|
||||||
|
filestore_subfolder = filestore_path / "filestore"
|
||||||
|
if filestore_subfolder.exists():
|
||||||
|
for file in filestore_subfolder.iterdir():
|
||||||
|
shutil.move(file, filestore_path)
|
||||||
|
shutil.rmtree(filestore_subfolder)
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,38 @@ def test_cli_restoredb(mocker):
|
||||||
# check filestore exists
|
# check filestore exists
|
||||||
assert dest_filestore_path.exists()
|
assert dest_filestore_path.exists()
|
||||||
|
|
||||||
|
# check the filestore content is at the right place
|
||||||
|
assert (dest_filestore_path / "01").exists()
|
||||||
|
|
||||||
|
# Check database exists
|
||||||
|
assert_database(ctx, db_name, "present")
|
||||||
|
|
||||||
|
# Delete filestore and database
|
||||||
|
shutil.rmtree(dest_filestore_path)
|
||||||
|
ensure_database(ctx, db_name, state="absent")
|
||||||
|
|
||||||
|
shutil.copyfile(
|
||||||
|
pathlib.Path("../restoredb/test_with_nested_filestore_dir.tar.gz"),
|
||||||
|
filestore_path,
|
||||||
|
)
|
||||||
|
|
||||||
|
cli_runner_invoke(
|
||||||
|
[
|
||||||
|
"restoredb",
|
||||||
|
f"--database={db_name}",
|
||||||
|
f"--database-path={database_path}",
|
||||||
|
"--database-format=c",
|
||||||
|
f"--filestore-path={filestore_path}",
|
||||||
|
"--filestore-format=tgz",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
# check filestore exists
|
||||||
|
assert dest_filestore_path.exists()
|
||||||
|
|
||||||
|
# check the filestore content is at the right place
|
||||||
|
assert (dest_filestore_path / "01").exists()
|
||||||
|
|
||||||
# Check database exists
|
# Check database exists
|
||||||
assert_database(ctx, db_name, "present")
|
assert_database(ctx, db_name, "present")
|
||||||
|
|
||||||
|
|
|
||||||
Binary file not shown.
BIN
tests/data/restoredb/test_with_nested_filestore_dir.tar.gz
Normal file
BIN
tests/data/restoredb/test_with_nested_filestore_dir.tar.gz
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user