Skip to content

Instantly share code, notes, and snippets.

@Lewiscowles1986
Created August 2, 2016 11:56
Show Gist options
  • Save Lewiscowles1986/c2588d30fff9d254afde47f024294fe1 to your computer and use it in GitHub Desktop.
Save Lewiscowles1986/c2588d30fff9d254afde47f024294fe1 to your computer and use it in GitHub Desktop.
WordPress Migrate Site

Migrate WordPress Site Using WP-CLI

This set of tools is for migrating WordPress systems using WP-CLI. It's released under AGPL with no implied warranty, support, etc.

Folder Structure

The tool requires a web-root folder structure where wp-content is not in the web-root but instead under a directory called public

  • $webroot
    • public (where WordPress lives under wp-content)

It creates a backup folder, where it saves an SQL dump

Troubleshooting

Currently only two plugins have caused any issues with this script

  • Buckaroo payment gateway for WooCommerce
  • Redirection

We advise disabling both plugins during operation of this script, then re-enabling after running

#!/bin/bash
if [ "$EUID" -ne 0 ]
then echo "Must be root"
exit
fi
if[ $# -ne 3 ]; then
echo "Sorry, we need both the source site, and the destination site"
echo "Usage:"
echo "${0} SRCSITE DESTSITE WWWDIR"
exit
fi
SRCSITE=$1
DSTSITE=$2
WWWDIR=$3
cd WWWDIR
mkdir -p backup
cd backup
mv ../public/wp-content/plugins/woocommerce-buckaroo-gateway ../public/wp-content/plugins/wp-buckaroo
wp search-replace $SRCSITE $DSTSITE --all-tables --precise --recurse-objects --export=migrate-`date +"%Y-%m-%d-%H%M"`.sql --path=`pwd`/../public
mv ../public/wp-content/plugins/wp-buckaroo ../public/wp-content/plugins/woocommerce-buckaroo-gateway
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment