Skip to content

Instantly share code, notes, and snippets.

@freegenie
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save freegenie/a94c1b4430bb5f4b0568 to your computer and use it in GitHub Desktop.
Save freegenie/a94c1b4430bb5f4b0568 to your computer and use it in GitHub Desktop.
Restore a wordpress instance from a WPEngine backup
#/bin/bash -l
# set -e # intentionally disabled
REMOTE_URL=$1 # Remote URL where to download the wpengine snapshot zip
DOMAIN=$2 # The new domain nme to use
GROUP=www-data
MYSQL_PW='your-password' # your database password even with special chars inside like >!- etc
USER=`stat --format '%U' . ` # this line takes the username from the owner of the current folder
cd public # assumes you'll install in a `public` directory in your space
wget $REMOTE_URL # download remote URL
unzip -n site-archive*.zip
rm -f site-archive*.zip
chown -R $USER.$GROUP .
# Remove WPengine specific plugins
rm -rf wp-content/mu-plugins
rm wp-content/object-cache.php
# Find and replace the domain in dump
sed -e "s#http://$USER.wpengine.com#http://$DOMAIN#g" wp-content/mysql.sql > wp-content/newdump.sql
MYSQL_COMMAND="mysql -u$USER -p'$MYSQL_PW'"
echo $MYSQL_COMMAND
DROP_COMMAND="$MYSQL_COMMAND -e ' DROP database $USER' ; "
echo $DROP_COMMAND
echo $DROP_COMMAND | sh # This trick allows for special chars in password to be evaluated correctly
CREATE_COMMAND="$MYSQL_COMMAND -e ' CREATE database $USER' ; "
echo $CREATE_COMMAND
echo $CREATE_COMMAND | sh
echo "DATABASE CREATED"
IMPORT_COMMAND="$MYSQL_COMMAND $USER < wp-content/newdump.sql "
echo "$IMPORT_COMMAND"
echo "$IMPORT_COMMAND" | sh
rm -f wp-content/*.sql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment