Skip to content

Instantly share code, notes, and snippets.

@boborchard
Created November 25, 2019 17:38
Show Gist options
  • Save boborchard/9516bfd389840268cb3e47a9ae077c07 to your computer and use it in GitHub Desktop.
Save boborchard/9516bfd389840268cb3e47a9ae077c07 to your computer and use it in GitHub Desktop.
Migrating a WordPress site using a shell script and WP-CLI
#!/bin/sh
# Unpack the payload
mkdir 'backup'
unzip '*.zip' -d backup
# Move down to the files directory for wp-cli
cd files
# Grab the credentials out of wp-config.php
WPDBNAME=`cat wp-config.php | grep DB_NAME | cut -d \' -f 4`
WPDBUSER=`cat wp-config.php | grep DB_USER | cut -d \' -f 4`
WPDBPASS=`cat wp-config.php | grep DB_PASSWORD | cut -d \' -f 4`
# Import the Database
wp db clean
wp db import ../backup/backup.sql
# Update old URLs
read -p 'Original Domain (with http): ' originaldomain
read -p 'New Domain (with http): ' newdomain
wp search-replace $originaldomain $newdomain
wp cache flush
# Move up to root
cd ~
# Move everything to /wp-content
rsync -avh --progress backup/files/wp-content/ files/wp-content
# Clean up
rm -rf ~/backup
rm -rf ~/migrate.sh
rm -rf ~/*.sql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment