From 51c4dc0b8bc97d1d8771d67e0825f203e8817922 Mon Sep 17 00:00:00 2001 From: dimti Date: Tue, 4 Jun 2024 12:01:38 +0300 Subject: [PATCH] + sync script for wp uploads --- quick/settings.sh.example | 13 ++++++++--- .../sync-uploads-from-prod-to-local.sh.example | 27 ++++++++++++++++++++++ 2 files changed, 37 insertions(+), 3 deletions(-) create mode 100755 quick/sync/sync-uploads-from-prod-to-local.sh.example diff --git a/quick/settings.sh.example b/quick/settings.sh.example index dc98556..37757cc 100755 --- a/quick/settings.sh.example +++ b/quick/settings.sh.example @@ -1,10 +1,10 @@ #!/bin/bash -SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +SETTINGS_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -export TMP_DIR=$SCRIPT_DIR/tmp +export TMP_DIR=$SETTINGS_SCRIPT_DIR/tmp export PROJECT_NAME=wpstudio -export PROJECT_WEB_ROOT="${SCRIPT_DIR}/.." +export PROJECT_WEB_ROOT="${SETTINGS_SCRIPT_DIR}/.." export TABLE_PREFIX="wp_" @@ -12,3 +12,10 @@ export PROD_DOMAIN=wpstudio.ru export LOCAL_DOMAIN=wpstudio.local.wpstudio.ru export THEME=nicol + +export SSH_PORT=22 + +export SSH_PROD_USERNAME=wpstudio +export SSH_PROD_SERVER=wpstudio.ru + +export REMOTE_SITE_DIR=/var/www/html diff --git a/quick/sync/sync-uploads-from-prod-to-local.sh.example b/quick/sync/sync-uploads-from-prod-to-local.sh.example new file mode 100755 index 0000000..e344799 --- /dev/null +++ b/quick/sync/sync-uploads-from-prod-to-local.sh.example @@ -0,0 +1,27 @@ +#!/bin/bash +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +. "${SCRIPT_DIR}/../settings.sh" || { + echo "no settings" && exit 1 +} + +UPLOAD_DIR="wp-content/uploads" + +SOURCE_UPLOADS_PATH="${REMOTE_SITE_DIR}/${UPLOAD_DIR}" + +DESTINATION_UPLOADS_PATH=$(realpath "${SCRIPT_DIR}/../../${UPLOAD_DIR}") + +if [ -z "$DESTINATION_UPLOADS_PATH" ]; then + echo "DESTINATION_UPLOADS_PATH is empty" && exit 1 +fi + +CMD="rsync -a --info=progress2 $SSH_PROD_USERNAME@$SSH_PROD_SERVER:$SOURCE_UPLOADS_PATH/ $DESTINATION_UPLOADS_PATH/" + +# shellcheck disable=SC2145 +echo "Execute: ${CMD}" +read -p "Are you sure? " -n 1 -r +echo # (optional) move to a new line +if [[ $REPLY =~ ^[Yy]$ ]] +then + /bin/bash -c "${CMD}" +fi