Skip to content

Instantly share code, notes, and snippets.

@heggemsnes
Created January 20, 2021 14:40
Show Gist options
  • Save heggemsnes/6d3acf5aafd18b22611e0f3973196e6d to your computer and use it in GitHub Desktop.
Save heggemsnes/6d3acf5aafd18b22611e0f3973196e6d to your computer and use it in GitHub Desktop.
Local WP pull DB and import to site
# Requires WP Cli and access to Local SSH, can be opened through Local GUI
# Need .env file in directory with format:
#SSH_USER=demo
#SSH_SERVER=ssh.url
#LIVE_SITE_URL=https://live.url
#LOCAL_SITE_URL=http://local.local
# get-env.sh
SSH_USER=$(grep SSH_USER .env | xargs)
SSH_USER=${SSH_USER#*=}
SSH_SERVER=$(grep SSH_SERVER .env | xargs)
SSH_SERVER=${SSH_SERVER#*=}
LIVE_SITE_URL=$(grep LIVE_SITE_URL .env | xargs)
LIVE_SITE_URL=${LIVE_SITE_URL#*=}
LOCAL_SITE_URL=$(grep LOCAL_SITE_URL .env | xargs)
LOCAL_SITE_URL=${LOCAL_SITE_URL#*=}
# pull-db.sh
# If your path to WP is different you might need to change this
. get-env.sh
wp db export backup.sql
ssh ${SSH_USER}@${SSH_SERVER} cd public && wp db export remotedb.sql
scp ${SSH_USER}@${SSH_SERVER}:public/remotedb.sql ./remotedb.sql
wp db import remotedb.sql
ssh ${SSH_USER}@${SSH_SERVER} rm -rf remotedb.sql
wp search-replace ${LIVE_SITE_URL} ${LOCAL_SITE_URL}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment