Last active
May 26, 2022 13:46
-
-
Save thetoine/5a09de20801e6e801834647899e4800b to your computer and use it in GitHub Desktop.
Docker mysql export bash script tool
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
#!/usr/bin/env bash | |
# Backup usage | |
# | |
# ./docker-db-export.sh backup my-project-folder-name_db_1 | |
# | |
# output to : ./my-project-folder-name_db_1.sql | |
# Restore usage | |
# | |
# ./docker-db-export.sh restore my-project-folder-name_db_1 my-project-folder-name_db_1.sql | |
TYPE="$1"; | |
CONTAINER_NAME="$2"; | |
MYSQL_FILENAME="$3"; | |
DB_NAME="wordpress"; | |
if [[ $TYPE == 'backup' ]]; then | |
echo "Backuping $CONTAINER_NAME"; | |
docker exec $CONTAINER_NAME /usr/bin/mysqldump -u root --password=root $DB_NAME > $CONTAINER_NAME.sql; | |
elif [[ $TYPE == 'restore' ]]; then | |
echo "Restoring $CONTAINER_NAME"; | |
cat $MYSQL_FILENAME | docker exec -i $CONTAINER_NAME /usr/bin/mysql -u root --password=root $DB_NAME; | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment