Last active
October 16, 2015 21:41
-
-
Save thenbrent/3632844 to your computer and use it in GitHub Desktop.
Sometimes, you just want to start with a clean slate
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 | |
# Drop the existing content of a database and replace it with a backup | |
DBUSER="root" | |
DBPASS="root" | |
DBNAME="INSERT-DB-NAME" | |
IMPORTFILE="$DBNAME.sql" | |
echo ".........................................." | |
echo -e " Enter the name of the DB backup (with extension): \c" | |
read IMPORTFILE | |
if [ -z "$IMPORTFILE" ] | |
then | |
IMPORTFILE="$DBNAME.sql" | |
echo ".........................................." | |
echo " *** No DB file entered, defaulting to $IMPORTFILE" | |
fi | |
echo ".........................................." | |
echo " Dropping the $DBNAME database" | |
CMD="DROP DATABASE $DBNAME;" | |
mysql -u "$DBUSER" -p"$DBPASS" -e "$CMD" | |
echo ".........................................." | |
echo " Creating empty $DBNAME database " | |
CMD="CREATE DATABASE $DBNAME;" | |
mysql -u "$DBUSER" -p"$DBPASS" -e "$CMD" | |
echo ".........................................." | |
echo " Importing $IMPORTFILE into $DBNAME " | |
mysql -u "$DBUSER" -p"$DBPASS" "$DBNAME" < "$IMPORTFILE" | |
echo ".........................................." | |
echo " $DBNAME is now a clean slate " | |
echo ".........................................." |
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 | |
# Drop the existing content of a database and replace it with a backup | |
DBUSER="root" | |
DBPASS="root" | |
DBNAME="INSERT-DB-NAME" | |
EXPORTFILE="$DBNAME.sql" | |
echo ".........................................." | |
echo -e " Enter the name of the DB backup file (with extension): \c" | |
read EXPORTFILE | |
if [ -z "$EXPORTFILE" ] | |
then | |
EXPORTFILE="$DBNAME.sql" | |
echo ".........................................." | |
echo " *** No DB file entered, defaulting to $EXPORTFILE" | |
fi | |
echo ".........................................." | |
echo " Dumping the $DBNAME database" | |
mysqldump -u "$DBUSER" -p"$DBPASS" "$DBNAME" > "$EXPORTFILE" | |
echo ".........................................." | |
echo " $DBNAME has been dumped to $EXPORTFILE " | |
echo ".........................................." | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment