-
-
Save joseluisq/bb157bdc0ccfd86d562451b71afae1cf to your computer and use it in GitHub Desktop.
Bash script to take backup of all the databases of docker database container from the host.
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
#!/bin/bash | |
set -x | |
## Mention your database container name | |
container_name= | |
## Mention your mysql root password | |
mysql_root_password= | |
DATE=`date +%F-%H-%M-%S` | |
for database in `echo 'show databases;' | docker exec -i mysql mysql --user=root --password=$mysql_root_password | grep -v Database | grep -v information_schema | grep -v mysql | grep -v performance_schema` | |
do | |
echo $database | |
docker exec $container_name mysqldump -u root -p$mysql_root_password $database > $database-$DATE.sql && tar -zcvf $database-$DATE.tar.gz $database-$DATE.sql && rm $database-$DATE.sql && echo "$database-$DATE.tar.gz has been created on `date`" >> database_backup.log | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment