Browse Source

+ import prod to local database script with ssh native compression

+ lighten restore perms script because on small count of files - that is better speed
master
dimti 5 months ago
parent
commit
e5f35243e4
  1. 31
      quick/restore-perms-light.sh.example
  2. 3
      quick/settings.sh.example
  3. 24
      quick/sync/import-prod-database-to-local.sh.example

31
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

3
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

24
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"
Loading…
Cancel
Save