diff --git a/scripts/get_archive_db.sh b/scripts/get_archive_db.sh new file mode 100755 index 0000000..2cba484 --- /dev/null +++ b/scripts/get_archive_db.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +# This script is used to download the archive dump from the mina-archive-dumps bucket +# and extract the archive dump to the sql_scripts directory +# The script will download the archive dump for the last 5 days and extract the first available archive dump +# Usage: ./scripts/get_archive_db.sh +# Example: ./scripts/get_archive_db.sh mainnet + +MINA_NETWORK=${1} +MINA_ARCHIVE_DUMP_URL=${MINA_ARCHIVE_DUMP_URL:=https://storage.googleapis.com/mina-archive-dumps} +DUMP_TIME=0000 +SQL_SCRIPT_PATH=$(pwd)/sql_scripts +TAR_FILE_PATH=${SQL_SCRIPT_PATH}/o1labs-archive-dump.tar.gz + +mkdir -p ${SQL_SCRIPT_PATH} + +MAX_DAYS_LOOKBACK=5 +i=0 +while [ $i -lt $MAX_DAYS_LOOKBACK ]; do + DATE=$(date -d "$i days ago" +%G-%m-%d)_${DUMP_TIME} + STATUS_CODE=$(curl -s -o /dev/null --head -w "%{http_code}" "${MINA_ARCHIVE_DUMP_URL}/${MINA_NETWORK}-archive-dump-${DATE}.sql.tar.gz") + if [[ ! $STATUS_CODE =~ 2[0-9]{2} ]]; then + i=$((i + 1)) + else + echo "Download ${MINA_NETWORK}-archive-dump-${DATE}.sql.tar.gz" + curl "${MINA_ARCHIVE_DUMP_URL}/${MINA_NETWORK}-archive-dump-${DATE}.sql.tar.gz" -o ${TAR_FILE_PATH} + break + fi +done + +[[ $STATUS_CODE =~ 2[0-9]{2} ]] || echo "[WARN] Unable to find archive dump for ${MINA_NETWORK}" + +tar -xvf ${SQL_SCRIPT_PATH}/o1labs-archive-dump.tar.gz -C ${SQL_SCRIPT_PATH} +rm -f ${TAR_FILE_PATH} + +echo "Extracted ${MINA_NETWORK}-archive-dump-${DATE}.sql.tar.gz to ${SQL_SCRIPT_PATH}/${MINA_NETWORK}-archive-dump-${DATE}.sql" diff --git a/scripts/wait_for_pg.sh b/scripts/wait_for_pg.sh new file mode 100755 index 0000000..edd8fff --- /dev/null +++ b/scripts/wait_for_pg.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +# This script is used to check if PostgreSQL is available +# Usage: ./scripts/pg_ready.sh +# Example: ./scripts/pg_ready.sh localhost 5432 + +# Parameters +PG_HOST="${1:-localhost}" +PG_PORT="${2:-5432}" + +# Wait for PostgreSQL to become available +until pg_isready -h "$PG_HOST" -p "$PG_PORT"; do + echo "Waiting for PostgreSQL to become available at ${PG_HOST}:${PG_PORT}..." + sleep 1 +done + +echo "PostgreSQL is available at ${PG_HOST}:${PG_PORT}" \ No newline at end of file