Skip to content

Instantly share code, notes, and snippets.

@kjakub
Last active May 9, 2017 11:06
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 kjakub/806a029d1a80d3be964a3e4282ae9497 to your computer and use it in GitHub Desktop.
Save kjakub/806a029d1a80d3be964a3e4282ae9497 to your computer and use it in GitHub Desktop.
Export and download mysql dump from mysql docker container - sshpass
#!/bin/bash
machine=""
user=""
password=""
container=""
mysql_user=""
mysql_password=""
database=""
if [ "$machine" == "" ]; then
echo -n SSH-machine:
read -s machine
fi
if [ "$user" == "" ]; then
echo -n SSH-user:
read -s user
fi
if [ "$password" == "" ]; then
echo -n SSH-Password:
read -s password
fi
if [ "$container" == "" ]; then
echo -n DOCKER-container:
read -s container
fi
if [ "$mysql_user" == "" ]; then
echo -n MYSQL-user:
read -s $mysql_user
fi
if [ "$mysql_password" == "" ]; then
echo -n MYSQL-password:
read -s $mysql_password
fi
if [ "$database" == "" ]; then
echo -n MYSQL-database:
read -s database
fi
echo
# Run Command
# echo $password
sshpass -p $password ssh $user@$machine << EOSSH
docker exec $container mysqldump -u $mysql_user --password=$mysql_password $database > dump.sql
EOSSH
sshpass -p $password scp -r $user@$machine:./dump.sql ./dump.sql
sshpass -p $password ssh $user@$machine << EOSSH
rm dump.sql
EOSSH
echo "saved dump.sql"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment