Skip to content

Instantly share code, notes, and snippets.

@nateflink
Last active December 18, 2015 14:39
Show Gist options
  • Save nateflink/5798915 to your computer and use it in GitHub Desktop.
Save nateflink/5798915 to your computer and use it in GitHub Desktop.
#!/bin/bash
#By Nate Flink
#
# get the wp-config mysql variables
#
DIRPATH=$1
VAR=$(curl -s https://gist.github.com/nateflink/06c5f5f99002374fe628/raw/readwpconfig.sh | bash -s "${DIRPATH}/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]}
#
# export mysql database
#
VAR=$(curl -s https://gist.github.com/nateflink/5790798/raw/mysqldump.sh | bash -s $WPDBNAME $WPDBUSER $WPDBPASS $WPDBHOST "${DIRPATH}/backup.sql")
STATUS=$?; [[ $STATUS == 0 ]] || { echo "${0} line:${LINENO} exit:$STATUS ${VAR}"; exit 2; }
#
# make a copy of wordpress files to /tmp directory
#
DATE=`date +%Y-%m-%d_%H:%M:%S`
DIRS=(${DIRPATH//\// })
TMPPATH="/tmp/"${DIRS[${#DIRS[@]} - 1]}"_$DATE"
cp -rp ${DIRPATH} ${TMPPATH}
echo "${TMPPATH}";
exit 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment