-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9b36b19
commit 38a068a
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <MINA_NETWORK> | ||
# 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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/bash | ||
|
||
# This script is used to check if PostgreSQL is available | ||
# Usage: ./scripts/pg_ready.sh <PG_HOST> <PG_PORT> | ||
# 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}" |