-
-
Save xdevmaycry/ad87e98feb88eb757c54ed1af19aff99 to your computer and use it in GitHub Desktop.
Backup and restore a mysql database from a running Docker mysql container
This file contains hidden or 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
############### | |
# MODIFIED FOR SECURITY | |
# | |
# This assumes we have the following environmental variables setup through docker composer configuration | |
# MYSQL_DB | |
# MYSQL_USER | |
# MYSQL_PASSWORD | |
############### | |
# Backup | |
docker exec CONTAINER /usr/bin/mysqldump -u "$MYSQL_USER" -p "$MYSQL_PASSWORD" "$MYSQL_DB" > backup.sql | |
# Restore | |
cat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -u "$MYSQL_USER" -p "$MYSQL_PASSWORD" "$MYSQL_DB" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment