Last active
May 1, 2020 00:53
-
-
Save gmhabchi/74986f14d2217c6e1363ca378e95ae99 to your computer and use it in GitHub Desktop.
SQL Migration
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 | |
sql_dump() { | |
echo "Performing mysqldump on database $DBNAME @ $HOST" | |
MYSQL_PWD=$PASSWORD mysqldump -h $HOST -P 3306 -u root $DBNAME > $DBNAME.sql | |
} | |
restore() { | |
echo "Performing restore on database $DBNAME @ $HOST" | |
MYSQL_PWD=$PASSWORD mysql -h $HOST -P 3306 -u root $DBNAME < $DBNAME.sql | |
} | |
# Get input | |
read -p 'Function: sql_dump or restore: ' FUNCTION | |
read -p 'DBName: ' DBNAME | |
read -p 'Host: ' HOST | |
read -sp 'Password: ' PASSWORD | |
if [[ -z $FUNCTION || -z $DBNAME || -z $HOST || -z $PASSWORD ]] | |
then | |
echo "Not all params supplied" | |
else | |
if [ "$FUNCTION" == "sql_dump" ] | |
then | |
sql_dump | |
elif [ "$FUNCTION" == "restore" ] | |
then | |
restore | |
else | |
echo "Please use either 'sql_dump' or 'restore' as function" | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment