Last active
May 9, 2017 11:06
-
-
Save kjakub/806a029d1a80d3be964a3e4282ae9497 to your computer and use it in GitHub Desktop.
Export and download mysql dump from mysql docker container - sshpass
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 | |
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