Created
October 7, 2022 13:03
-
-
Save roboli/ddffa487c414650c22047db8a17c2179 to your computer and use it in GitHub Desktop.
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 | |
function print-help() { | |
echo "Clone database, use locally only." | |
echo "" | |
echo " mysql_clone username password old_db new_db" | |
echo "" | |
echo "Options:" | |
echo "" | |
echo " username: Database username from where you want to copy database" | |
echo "" | |
echo " password: Database password from where you want to copy database" | |
echo "" | |
echo " old_db: Database from where you want to copy" | |
echo "" | |
echo " new_db: Database to where you want to copy, will be created for you" | |
echo "" | |
} | |
if [ "$#" -eq 1 ] && ([ "$1" = "-h" ] || [ "$1" = "--help" ]); | |
then | |
print-help | |
exit 0 | |
fi | |
if [ "$#" -ne 4 ]; | |
then | |
echo "Invalid number of parameters. Use -h or --help for more info." | |
exit 1 | |
fi | |
echo "CREATE DATABASE $4" | mysql -u $1 --password=$2 | |
mysqldump $3 -u $1 --password=$2 | mysql -u $1 --password=$2 $4 | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment