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

  1. #!/bin/bash
  2. SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
  3. . $SCRIPT_DIR/_settings.sh || {
  4. echo "no settings" && exit 1
  5. }
  6. REMOTE_FROM_DATABASE_USERNAME=some_username
  7. REMOTE_FROM_DATABASE_PASSWORD=some_password
  8. REMOTE_FROM_DATABASE_NAME=some_database
  9. DATABASE_USERNAME=site_name
  10. DATABASE_PASSWORD='password'
  11. DATABASE_NAME=site_name
  12. echo -n "SSH connection verify... "
  13. ssh $REMOTE_SSH_USER@$REMOTE_SSH_HOST -p $REMOTE_SSH_PORT "whoami"
  14. if [[ "$?" -ne 0 ]]; then
  15. echo "That is not ok... Abort program!"
  16. exit 1
  17. fi
  18. WITHOUT_DROP_LOCAL_DB=0
  19. if [[ ! -z "$1" ]]; then
  20. WITHOUT_DROP_LOCAL_DB=1
  21. fi
  22. if [[ $WITHOUT_MAKE_DUMP -ne 1 ]]; then
  23. echo -n "Drop and recreate local database... "
  24. mariadb -e "DROP DATABASE \`${DATABASE_NAME}\`"
  25. mariadb -e "CREATE DATABASE \`${DATABASE_NAME}\`"
  26. fi
  27. echo -n "Loading database from remote server... "
  28. ssh $REMOTE_SSH_USER@$REMOTE_SSH_HOST -p $REMOTE_SSH_PORT \
  29. "mysqldump -u $REMOTE_FROM_DATABASE_USERNAME -p$REMOTE_FROM_DATABASE_PASSWORD $REMOTE_FROM_DATABASE_NAME | bzip2 -c" \
  30. | pv | bzip2 -cd | mariadb -u $DATABASE_USERNAME -p''"$DATABASE_PASSWORD"'' ${DATABASE_NAME}
  31. echo "OK"