Created
May 24, 2015 12:17
-
-
Save mathse/04c613c0aac833df86d9 to your computer and use it in GitHub Desktop.
mysqldump all mysql containers
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
!/bin/bash | |
ymlfiles=/my/docker/compose/containers | |
backupdir=/my/backups | |
for file in $(grep -lr "image: mysql" $ymlfiles/*/*.yml) | |
do | |
pw=$(grep MYSQL_ROOT_PASSWORD $file | cut -d"=" -f2) | |
port=$(grep 3306 $file | sed -E 's/[-" ]+([0-9]+):([0-9]+)[-" ]+/\1/') | |
name=$(echo $file | cut -d'/' -f5) | |
mysqldump -hlocalhost --protocol=tcp -uroot -p$pw -P$port --all-databases > $backupdir/db-$name-$(date +%Y-%m-%d-%H-%M-%S).sql | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment