Skip to content

Instantly share code, notes, and snippets.

@nateflink
Created June 18, 2013 19:04
Show Gist options
  • Save nateflink/5808260 to your computer and use it in GitHub Desktop.
Save nateflink/5808260 to your computer and use it in GitHub Desktop.
#!/bin/bash
WPPATH=$1
REMOTE_WPPATH=$2
SSH_USER=$3
SSH_URL=$4
LOCAL_HOSTNAME=$5
REMOTE_HOSTNAME=$6
#
# copy the remote wp installation to the remote tmp directory
#
REMOTE_TMPPATH=$(ssh ${SSH_USER}@${SSH_URL} '\
VAR=$(curl -s https://gist.github.com/nateflink/5798915/raw/copywp.sh | bash -s '${REMOTE_WPPATH}' );\
STATUS=$?; [[ $STATUS == 0 ]] || { echo "${0} line:${LINENO} exit:$STATUS ${VAR}"; exit 1; };\
echo $VAR\
')
#echo $REMOTE_TMPPATH
#
# copy local wp installation to a tmp location
#
TMPPATH=$(curl -s https://gist.github.com/nateflink/5798915/raw/copywp.sh | bash -s ${WPPATH} )
STATUS=$?; [[ $STATUS == 0 ]] || { echo "${0} line:${LINENO} exit:$STATUS ${VAR}"; exit 1; }
#echo $TMPPATH
#
# find and replace urls in the temp path location
#
VAR=$(curl -s https://gist.github.com/nateflink/5793139/raw/findreplace.sh | bash -s ${TMPPATH} ${LOCAL_HOSTNAME} ${REMOTE_HOSTNAME})
STATUS=$?; [[ $STATUS == 0 ]] || { echo "${0} line:${LINENO} exit:$STATUS ${VAR}"; exit 1; }
#
# copy the tmp local wordpress to the remote location
#
rsync -r -v -l --exclude ".*" --include=".htaccess" ${TMPPATH}/ ${SSH_USER}@${SSH_URL}:"${REMOTE_TMPPATH}"
#
# switch the old wp with the new wp and import mysql database
#
DATE=`date +%Y-%m-%d_%H:%M:%S`
DIRS=(${REMOTE_WPPATH//\// })
REMOTE_BACKUPPATH="./"${DIRS[${#DIRS[@]} - 1]}"_$DATE"
RMVAR=$(ssh ${SSH_USER}@${SSH_URL} '\
mv '${REMOTE_WPPATH}' '${REMOTE_BACKUPPATH}';\
mv '${REMOTE_TMPPATH}' '${REMOTE_WPPATH}';\
VAR=$(curl -s https://gist.github.com/nateflink/06c5f5f99002374fe628/raw/readwpconfig.sh | bash -s "'${REMOTE_WPPATH}'/wp-config.php");\
STATUS=$?; [[ $STATUS == 0 ]] || { echo "${0} line:${LINENO} exit:$STATUS ${VAR}"; exit 1; };\
IFS=" " read -a ARR <<< "${VAR}";\
WPDBNAME=${ARR[0]};\
WPDBUSER=${ARR[1]};\
WPDBPASS=${ARR[2]};\
WPDBHOST=${ARR[3]};\
mysql -u ${WPDBUSER} -p${WPDBPASS} -h ${WPDBHOST} ${WPDBNAME} < '${REMOTE_WPPATH}'/backup.sql;\
')
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment