-
-
Save nk-gears/a1a44feb725f2cb6758fc427fe93ce7e to your computer and use it in GitHub Desktop.
Backup and restore a ALL MySQL databases 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
CONTAINER=db | |
# Backup | |
docker exec $CONTAINER sh -c \ | |
'mysqldump --all-databases --quick --single-transaction --skip-lock-tables --flush-privileges -uroot -p"$MYSQL_ROOT_PASSWORD"' \ | |
| gzip > ./backup.sql.gz | |
# Restore | |
gunzip ./backup.sql.gz | |
cat backup.sql | docker exec -i $CONTAINER sh -c 'mysql -uroot -p"$MYSQL_ROOT_PASSWORD"' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment