Last active
May 21, 2018 16:33
-
-
Save Natata/95059f6381a9e5c889dde35a91209a46 to your computer and use it in GitHub Desktop.
backup running mysql in docker
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/sh | |
# how to use: | |
# ./backup.sh mysql_prod root rootpw mydb /var/log/backup.sql | |
# crontab example: | |
# 0 0 * * * /backup.sh mysql_prod root rootpw mydb /var/log/backup.sql | |
# restore example: | |
# cat backup.sql | docker exec -i [container_name] /usr/bin/mysql -u [mysql_user] --password=[mysql_password] [database_name] | |
set -uex | |
container_name=$1 | |
mysql_user=$2 | |
mysql_password=$3 | |
db_name=$4 | |
file_path=$5 | |
if [ ! "$(docker ps | grep $container_name)" ]; then | |
exit 1; | |
fi | |
docker exec $container_name /usr/bin/mysqldump -u root -p"$mysql_password" $db_name > $file_path |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment