Skip to content

Instantly share code, notes, and snippets.

@ashmore11
Last active January 19, 2021 21:41
Show Gist options
  • Save ashmore11/941f2525a9a1dfbe80265d88fa25d99c to your computer and use it in GitHub Desktop.
Save ashmore11/941f2525a9a1dfbe80265d88fa25d99c to your computer and use it in GitHub Desktop.
Next Strapi Cloud Run (pipelines sync db bash)
#! /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