Created
December 1, 2020 09:05
-
-
Save theredhead/58a602afecd1aaa294fba46b87db3c11 to your computer and use it in GitHub Desktop.
Backup and restore mysql databases running in docker containers (from docker host shell)
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
# CONTAINER_ID => value of container id column from `docker ps` | |
# DATABASE_NAME => name of the mysql database to backup/restore | |
# Backup to backup-file.sql outside container | |
docker exec CONTAINER_ID /usr/bin/mysqldump --triggers --routines -uMYSQL_USER -pMYSQL_PASSWORD DATABASE_NAME > backup-file.sql | |
# Restore from backup-file.sql outside container | |
cat backup-file.sql | docker exec -i CONTAINER_ID /usr/bin/mysql -uMYSQL_USER -pMYSQL_PASSWORD DATABASE_NAME |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment