You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.1 KiB
41 lines
1.1 KiB
#!/bin/bash
|
|
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
|
|
. $SCRIPT_DIR/_settings.sh || {
|
|
echo "no settings" && exit 1
|
|
}
|
|
|
|
REMOTE_FROM_DATABASE_USERNAME=some_username
|
|
REMOTE_FROM_DATABASE_PASSWORD=some_password
|
|
REMOTE_FROM_DATABASE_NAME=some_database
|
|
|
|
DATABASE_USERNAME=site_name
|
|
DATABASE_PASSWORD='password'
|
|
DATABASE_NAME=site_name
|
|
|
|
|
|
echo -n "SSH connection verify... "
|
|
ssh $REMOTE_SSH_USER@$REMOTE_SSH_HOST -p $REMOTE_SSH_PORT "whoami"
|
|
|
|
if [[ "$?" -ne 0 ]]; then
|
|
echo "That is not ok... Abort program!"
|
|
exit 1
|
|
fi
|
|
|
|
WITHOUT_DROP_LOCAL_DB=0
|
|
|
|
if [[ ! -z "$1" ]]; then
|
|
WITHOUT_DROP_LOCAL_DB=1
|
|
fi
|
|
|
|
if [[ $WITHOUT_MAKE_DUMP -ne 1 ]]; then
|
|
echo -n "Drop and recreate local database... "
|
|
mariadb -e "DROP DATABASE \`${DATABASE_NAME}\`"
|
|
mariadb -e "CREATE DATABASE \`${DATABASE_NAME}\`"
|
|
fi
|
|
|
|
echo -n "Loading database from remote server... "
|
|
ssh $REMOTE_SSH_USER@$REMOTE_SSH_HOST -p $REMOTE_SSH_PORT \
|
|
"mysqldump -u $REMOTE_FROM_DATABASE_USERNAME -p$REMOTE_FROM_DATABASE_PASSWORD $REMOTE_FROM_DATABASE_NAME | bzip2 -c" \
|
|
| pv | bzip2 -cd | mariadb -u $DATABASE_USERNAME -p''"$DATABASE_PASSWORD"'' ${DATABASE_NAME}
|
|
echo "OK"
|