Skip to content

Instantly share code, notes, and snippets.

@kohmaeda
Created July 12, 2016 07:14
Show Gist options
  • Save kohmaeda/9e4b5b3756c8fbdac7cc9d891ec689db to your computer and use it in GitHub Desktop.
Save kohmaeda/9e4b5b3756c8fbdac7cc9d891ec689db to your computer and use it in GitHub Desktop.
#!/bin/bash
# Migrates the database from your Trellis/bedrock/sage remote server to your local box, and syncs the WP uploads folder as a bonus. It will ruthlessly overwrite your local database, so be careful.
WEB_USER="web" # or root, using web makes files have the correct permissions for WP
WEB_URL=""
LOCAL_URL="192.168.50.5"
VAGRANT_ID="" # $ vagrant global-status
WP_DIR="" #/srv/www/(sitename)
LOCAL_DIR="" # /users/... (sitename)/site/web/app/uploads/
# Export DB from production machine and change the site name to the dev one
ssh -t $WEB_USER@$WEB_URL "cd $WP_DIR/current/web && wp db export $WP_DIR/shared/uploads/db/production.sql && sed 's/\/\/$WEB_URL/\/\/$LOCAL_URL/g' $WP_DIR/shared/uploads/db/production.sql > $WP_DIR/shared/uploads/db/dev.sql;"
# Sync uploads folder between production and local
rsync -rav $WEB_USER@$WEB_URL:$WP_DIR/shared/uploads/ $LOCAL_DIR
# Import production db to dev box
vagrant ssh $VAGRANT_ID -- -t "cd $WP_DIR/current/web && wp db import app/uploads/db/dev.sql;"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment