Skip to content

Instantly share code, notes, and snippets.

@zetrider
Created November 19, 2015 12:54
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 zetrider/d0e520d1cdaf35ab5dc8 to your computer and use it in GitHub Desktop.
Save zetrider/d0e520d1cdaf35ab5dc8 to your computer and use it in GitHub Desktop.
Дамп базы данных с удаленного сервера на Localhost
#!/bin/sh
# 1. https://gist.github.com/zetrider/28f1d463c6bd9af1c0e6
# 2. $1 = type !important
if [ -z $1 ]; then
echo 'Not found the first variable "Type"'
exit;
fi;
### Site1 ###
if [ $1 = 'S1' ]; then
HOST='user@server.ru'
DB_USER='user'
DB_PASS='password'
DB_NAME='base'
DB_LOCAL='base_local';
DUMP_NAME=$DB_NAME'_'`date +%Y_%m_%d`'.sql'
echo 'Connect to the: '$HOST
echo 'Download database: '$DB_NAME
ssh $HOST mysqldump -u $DB_USER -p$DB_PASS $DB_NAME > $DUMP_NAME
echo 'The file was created: '$DUMP_NAME
fi
### Copy to the Localhost ###
if [ -s $DUMP_NAME ]; then
echo 'Import to the: Localhost'
# Your mysql
/Applications/MAMP/Library/bin/mysql -u root -proot $DB_LOCAL < $DUMP_NAME
echo 'Completed the import into the: Localhost'
rm $DUMP_NAME;
else
echo 'Error: File is not exist'
fi;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment