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