Browse Source

+ quick sync from old prod server scripts

master
dimti 7 months ago
parent
commit
2d56599c73
  1. 1
      server/quick/sync-old-prod/.gitignore
  2. 4
      server/quick/sync-old-prod/_settings.sh.example
  3. 41
      server/quick/sync-old-prod/sync-database.sh.example
  4. 14
      server/quick/sync-old-prod/sync-uploads.sh.example

1
server/quick/sync-old-prod/.gitignore

@ -0,0 +1 @@
*.sh

4
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

41
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"

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