Skip to content

Instantly share code, notes, and snippets.

@mathse
Created May 24, 2015 12:17
Show Gist options
  • Save mathse/04c613c0aac833df86d9 to your computer and use it in GitHub Desktop.
Save mathse/04c613c0aac833df86d9 to your computer and use it in GitHub Desktop.
mysqldump all mysql containers
!/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