Skip to content

Instantly share code, notes, and snippets.

@Natata
Last active May 21, 2018 16:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Natata/95059f6381a9e5c889dde35a91209a46 to your computer and use it in GitHub Desktop.
Save Natata/95059f6381a9e5c889dde35a91209a46 to your computer and use it in GitHub Desktop.
backup running mysql in docker
#!/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