From e5f35243e4be32d51c5937e54cfdf3fd2967d037 Mon Sep 17 00:00:00 2001 From: dimti Date: Tue, 18 Jun 2024 09:24:24 +0300 Subject: [PATCH] + import prod to local database script with ssh native compression + lighten restore perms script because on small count of files - that is better speed --- quick/restore-perms-light.sh.example | 31 ++++++++++++++++++++++ quick/settings.sh.example | 3 +++ .../sync/import-prod-database-to-local.sh.example | 24 +++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 quick/restore-perms-light.sh.example create mode 100644 quick/sync/import-prod-database-to-local.sh.example diff --git a/quick/restore-perms-light.sh.example b/quick/restore-perms-light.sh.example new file mode 100644 index 0000000..add9159 --- /dev/null +++ b/quick/restore-perms-light.sh.example @@ -0,0 +1,31 @@ +#!/bin/bash +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +WP_CONTENT_DIRS=( + plugins + upgrade + uploads + themes +) + +export WEB_GID=33 + +perms() { + sudo chown -R $UID:$WEB_GID "$1" + sudo chmod -R g+rwx "$1" +} + +permsFile() { + sudo chown $UID:$WEB_GID "$1" + sudo chmod g+rw "$1" +} + +for DIR in "${WP_CONTENT_DIRS[@]}"; do + DIR="$SCRIPT_DIR/../wp-content/$DIR" + + if [[ -f $DIR ]]; then + permsFile "$DIR" + else + perms "$DIR" + fi +done diff --git a/quick/settings.sh.example b/quick/settings.sh.example index 37757cc..125556d 100644 --- a/quick/settings.sh.example +++ b/quick/settings.sh.example @@ -18,4 +18,7 @@ export SSH_PORT=22 export SSH_PROD_USERNAME=wpstudio export SSH_PROD_SERVER=wpstudio.ru +export PROD_DATABASE_NAME=wpstudio +export LOCAL_DATABASE_NAME=wpstudio + export REMOTE_SITE_DIR=/var/www/html diff --git a/quick/sync/import-prod-database-to-local.sh.example b/quick/sync/import-prod-database-to-local.sh.example new file mode 100644 index 0000000..97bd770 --- /dev/null +++ b/quick/sync/import-prod-database-to-local.sh.example @@ -0,0 +1,24 @@ +#!/bin/bash +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +. "${SCRIPT_DIR}/../settings.sh" || { + echo "no settings" && exit 1 +} + +CONTAINER=$(docker ps | grep mariadb | awk '{print $1}') + +if [[ -z "${CONTAINER}" ]]; then + echo "Unable to find container: db" + exit 1 +fi + +MYSQL_CMD="docker exec -i ${CONTAINER} mariadb -u root -p123456" + +echo -n "Drop and recreate ${LOCAL_DATABASE_NAME} database... " +bash -c "${MYSQL_CMD} -e 'DROP DATABASE \`${LOCAL_DATABASE_NAME}\`'" +bash -c "${MYSQL_CMD} -e 'CREATE DATABASE \`${LOCAL_DATABASE_NAME}\`'" +echo "OK" + +echo -n "Importing prod dump data from $SSH_PROD_SERVER ... " +ssh -C ${SSH_PROD_USERNAME}@${SSH_PROD_SERVER} "mariadb-dump --defaults-extra-file=/home/${SSH_PROD_USERNAME}/.my.cnf ${PROD_DATABASE_NAME} | sed '1d'" | pv | bash -c "${MYSQL_CMD} ${LOCAL_DATABASE_NAME}" +echo "OK"