Skip to content

Instantly share code, notes, and snippets.

@fabean
Created December 5, 2019 13:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fabean/191b04a4eb5991faf16ca6e20b0c3782 to your computer and use it in GitHub Desktop.
Save fabean/191b04a4eb5991faf16ca6e20b0c3782 to your computer and use it in GitHub Desktop.
Database Sync Script
#!/bin/bash
echo "What do you want to do? (import/export)"
read dbtype
echo "What environment do you want? (dev/stage/prod)"
read environment
echo "What is the database name?"
read databasename
if [ "$environment" == "dev" ]; then
dbhost='dev-db-host'
elif [ "$environment" == "stage" ]; then
dbhost='stage-db-host'
elif [ "$environment" == "prod" ]; then
dbhost='prod-db-host'
else
dbhost=$environment
echo "Using Custom DB Host";
fi
if [ "$dbtype" == "import" ]; then
echo "What is the filename (give full path to file if not in this directory)"
read databasefile
if [ "$environment" == "prod" ]; then
echo "Since it's prod we are dumping db before import to $databasename-backup.sql"
mysqldump -h $dbhost $databasename > $databasename-backup.sql
fi
echo "Importing DB";
mysql -h $dbhost $databasename < $databasefile
elif [ "$dbtype" == "export" ]; then
echo "Dumping DB to $databasename.sql"
mysqldump -h $dbhost $databasename > $databasename-backup.sql
fi
echo "Have a great day!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment