Last active
January 19, 2021 21:41
-
-
Save ashmore11/941f2525a9a1dfbe80265d88fa25d99c to your computer and use it in GitHub Desktop.
Next Strapi Cloud Run (pipelines sync db bash)
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
#! /bin/bash | |
apt-get update && apt-get install default-mysql-client -y | |
query="SELECT count(*) AS TOTALNUMBEROFTABLES FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'production';" | |
tableCount=$(mysql -u "$DB_USERNAME" -p"$DB_PASSWORD" -h "$DB_HOST" -s -e "$query") | |
echo "" | |
echo "Starting database dump..." | |
if [[ $tableCount = "0" ]]; then | |
mysqldump -u "$DB_USERNAME" -p"$DB_PASSWORD" -h "$DB_HOST" "local" > dump.sql | |
else | |
mysqldump -u "$DB_USERNAME" -p"$DB_PASSWORD" -h "$DB_HOST" --no-create-info --replace "local" > dump.sql | |
fi | |
echo "Starting database sync..." | |
mysql -u "$DB_USERNAME" -p"$DB_PASSWORD" -h "$DB_HOST" "production" < dump.sql | |
echo "Database sync successful!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment