diff --git a/server/quick/sync-old-prod/.gitignore b/server/quick/sync-old-prod/.gitignore new file mode 100644 index 0000000..c97f963 --- /dev/null +++ b/server/quick/sync-old-prod/.gitignore @@ -0,0 +1 @@ +*.sh diff --git a/server/quick/sync-old-prod/_settings.sh.example b/server/quick/sync-old-prod/_settings.sh.example new file mode 100644 index 0000000..94f9d19 --- /dev/null +++ b/server/quick/sync-old-prod/_settings.sh.example @@ -0,0 +1,4 @@ +#!/bin/bash +REMOTE_SSH_USER=site_name +REMOTE_SSH_HOST=host_name +REMOTE_SSH_PORT=22 diff --git a/server/quick/sync-old-prod/sync-database.sh.example b/server/quick/sync-old-prod/sync-database.sh.example new file mode 100755 index 0000000..f61ad79 --- /dev/null +++ b/server/quick/sync-old-prod/sync-database.sh.example @@ -0,0 +1,41 @@ +#!/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" diff --git a/server/quick/sync-old-prod/sync-uploads.sh.example b/server/quick/sync-old-prod/sync-uploads.sh.example new file mode 100755 index 0000000..4cf2d21 --- /dev/null +++ b/server/quick/sync-old-prod/sync-uploads.sh.example @@ -0,0 +1,14 @@ +#!/bin/bash +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +. $SCRIPT_DIR/_settings.sh || { + echo "no settings" && exit 1 +} + +REMOTE_FROM_DIR_PATH=some_absolute_path_without_end_slash + +DESTINATION_DIR_PATH=/var/www/html/wp-content/uploads + +echo -n "Upload... " +rsync -a --info=progress2 -e "ssh -p ${REMOTE_SSH_PORT}" $REMOTE_SSH_USER@$REMOTE_SSH_HOST:$REMOTE_FROM_DIR_PATH/ $DESTINATION_DIR_PATH/ +echo "OK"