Forked from webkul/docker-db-container-backup.sh
Created
June 1, 2018 12:26
Star
You must be signed in to star a gist
Bash script to take backup of all the databases of docker database container from the host.
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 | |
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