Skip to content

Commit

Permalink
Add check-db continuity script to migrate.sh (#32)
Browse files Browse the repository at this point in the history
Adds a call to the check-db script in celo-migrate to migrate.sh.
This checks for gaps in the source directory and exits
immediately if gaps are found.

Adds some drive-by changes for things that came up during testing:

destination dir path should include "chaindata"
calls to readlink fail if path does not exist, so we check that the source directory exists before calling readlink on it
Tested locally using a baklava datadir with gaps and a baklava datadir without gaps
  • Loading branch information
alecps authored Feb 13, 2025
1 parent 8ff1c64 commit bd5a852
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions migrate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,42 @@ echo "Source Directory: $source_dir"
echo "Destination Directory: $destination_dir"
echo "" # Blank line to separate from any failure output

# Convert source and destination directories to absolute paths
# Check if source directory exists
if [ ! -d "${source_dir}" ]; then
printf "\033[0;31mError: Source directory does not exist\033[0m\n"
exit 1
fi

# Convert source directory to absolute path
source_dir=$(readlink -f "$source_dir")
destination_dir=$(readlink -f "$destination_dir")

cel2_migration_tool_image="us-west1-docker.pkg.dev/devopsre/celo-blockchain-public/cel2-migration-tool"
cel2_migration_tool_tag="5682b80ec60c47f582c6af8aa085ae6f9048d801"

# Run check-db continuity script to ensure source db has no data gaps
if docker run --platform=linux/amd64 -it --rm \
-v "${source_dir}/celo/chaindata:/old-db" \
"${cel2_migration_tool_image}:${cel2_migration_tool_tag}" \
check-db \
--db-path /old-db \
--fail-fast; then
printf "\033[0;32mDB check completed successfully. No gaps or missing data detected.\033[0m\n"
else
printf "\033[0;31mDB check failed with exit code $?. If the logs indicate that the db is missing data, please retry with another source db. You can visit https://docs.celo.org/cel2/operators/migrate-node for instructions on how to check whether a db has missing data.\033[0m\n"
exit $?
fi

# Ensure destination directory exists for chaindata
mkdir -p "${destination_dir}/geth"
mkdir -p "${destination_dir}/geth/chaindata"

# Convert destination directory to absolute path
destination_dir=$(readlink -f "$destination_dir")

if [ "${operation}" = "pre" ]; then
docker run --platform=linux/amd64 -it --rm \
-v "${source_dir}/celo/chaindata:/old-db" \
-v "${destination_dir}/geth/chaindata:/new-db" \
us-west1-docker.pkg.dev/devopsre/celo-blockchain-public/cel2-migration-tool:5682b80ec60c47f582c6af8aa085ae6f9048d801 \
"${cel2_migration_tool_image}:${cel2_migration_tool_tag}" \
"${operation}" \
--old-db /old-db \
--new-db /new-db
Expand Down Expand Up @@ -85,7 +109,7 @@ docker run --platform=linux/amd64 -it --rm \
-v "${destination_dir}/geth/chaindata:/new-db" \
-v "${migration_config_dir}:/migration-config" \
-v "./envs/${network}/config:/out-config" \
us-west1-docker.pkg.dev/devopsre/celo-blockchain-public/cel2-migration-tool:5682b80ec60c47f582c6af8aa085ae6f9048d801 \
"${cel2_migration_tool_image}:${cel2_migration_tool_tag}" \
"${operation}" \
--old-db /old-db \
--new-db /new-db \
Expand Down

0 comments on commit bd5a852

Please sign in to comment.