Skip to content

Instantly share code, notes, and snippets.

@cyberhobo
Last active December 17, 2015 17:39
Show Gist options
  • Save cyberhobo/5647721 to your computer and use it in GitHub Desktop.
Save cyberhobo/5647721 to your computer and use it in GitHub Desktop.
Beginnings at least of a shell script to refresh a local development WordPress site with the contents of a WPEngine archive. Uses [wp-cli](http://wp-cli.org).
#!/bin/bash
# exit on error
set -e
archive=$1
# one argument: the archive file
if [ ! -r "$archive" ]; then
echo "Usage: import-wpe-archive <zip-archive>"
exit 1
fi
if [ ! -r "wp-config.php" ]; then
echo "Use this command in the root of site to overwrite."
exit 1
fi
wp core is-installed
blogname=$( wp option get blogname )
home=$( wp option get home )
read -p "Overwrite '$blogname' with the contents of $archive? [y/n]" -n 1 -r
if [[ $REPLY =~ ^[Yy]$ ]]; then
excludes=( ".htaccess" ".gitignore" ".gitattributes" "wp-config.php" \
"wp-content/mu-plugins/wpengine-common/*" \
"wp-snapshots/*" \
"wp-content/updraft/*" \
"wp-content/mu-plugins/mu-plugin.php" \
"wp-content/object-cache.php" )
if ! unzip -u -o $archive -x "${excludes[@]}" 2> /dev/null; then
# ignore zip warnings of unmatched excludes
:
fi
wp db import wp-content/mysql.sql
wp option set blogname "$blogname"
newhome=$( wp option get home )
if [ "$home" != "$newhome" ]; then
read -p "Search and replace '$newhome' with '$home'? [y/n]" -n 1 -r
if [[ $REPLY =~ ^[Yy]$ ]]; then
wp search-replace --skip-columns=guid "$newhome" "$home"
fi
fi
echo "Imported $archive as '$blogname'."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment