Skip to content

Instantly share code, notes, and snippets.

@xdevmaycry
Forked from spalladino/mysql-docker.sh
Last active November 1, 2018 20:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xdevmaycry/ad87e98feb88eb757c54ed1af19aff99 to your computer and use it in GitHub Desktop.
Save xdevmaycry/ad87e98feb88eb757c54ed1af19aff99 to your computer and use it in GitHub Desktop.
Backup and restore a mysql database from a running Docker mysql container
###############
# 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