github.com/diadata-org/diadata@v1.4.593/testspace/import_snapshot.sh (about) 1 #!/bin/bash 2 3 # Function to check if a command exists 4 command_exists() { 5 command -v "$1" >/dev/null 2>&1 6 } 7 8 # Check if unzip, wget, and psql commands exist 9 if ! command_exists unzip; then 10 echo "Error: 'unzip' command not found. Please install unzip and try again." 11 exit 1 12 fi 13 14 if ! command_exists wget; then 15 echo "Error: 'wget' command not found. Please install wget and try again." 16 exit 1 17 fi 18 19 if ! command_exists psql; then 20 echo "Error: 'psql' command not found. Please install PostgreSQL client and try again." 21 exit 1 22 fi 23 24 # Ask for variables with _EXTRACT and export them 25 read -p "Enter Postgres Server: " PGHOST_EXTRACT 26 read -p "Enter Postgres Port: " PGPORT_EXTRACT 27 read -p "Enter Postgres User: " PGUSER_EXTRACT 28 read -p "Enter Postgres Password: " PGPASSWORD_EXTRACT 29 read -p "Enter Postgres Database: " PGDB_EXTRACT 30 31 export PGHOST=${PGHOST_EXTRACT} 32 export PGUSER=${PGUSER_EXTRACT} 33 export PGDB=${PGDB_EXTRACT} 34 export PGPASSWORD=${PGPASSWORD_EXTRACT} 35 export PGPORT=${PGPORT_EXTRACT} 36 37 # Download and unzip the file from rest.diadata.org 38 wget -qO snapshot.zip http://rest.diadata.org/snapshot/latest 39 unzip -o snapshot.zip 40 41 # Run the psql commands 42 psql --port ${PGPORT} --username ${PGUSER} --dbname ${PGDB} --file output-blockchain.sql 43 psql --port ${PGPORT} --username ${PGUSER} --dbname ${PGDB} --file output-exchange.sql 44 psql --port ${PGPORT} --username ${PGUSER} --dbname ${PGDB} --file output-asset.sql 45 psql --port ${PGPORT} --username ${PGUSER} --dbname ${PGDB} --file output-pool.sql 46 psql --port ${PGPORT} --username ${PGUSER} --dbname ${PGDB} --file output-poolasset.sql 47 psql --port ${PGPORT} --username ${PGUSER} --dbname ${PGDB} --file output-exchangepair.sql 48 49 # Delete the output-*.sql files 50 rm output-blockchain.sql 51 52 echo "Data import and processing completed successfully."