Skip to content

Instantly share code, notes, and snippets.

@chrisgrabinski
Last active May 9, 2018 13:42
Show Gist options
  • Save chrisgrabinski/e3dede75a9c57f9dfc75be042538a134 to your computer and use it in GitHub Desktop.
Save chrisgrabinski/e3dede75a9c57f9dfc75be042538a134 to your computer and use it in GitHub Desktop.
Sync database and media library between two WordPress installations with WP CLI
# WordPress Sync
# ---------------------------------------------------------------------------------
#!/bin/bash
src=SOURCEDIRECTORY
dest=DESTDIRECTORY
srcUrl=https://staging.source.com
destUrl=https://source.com
cd $src
# Create Database Dump
echo "🗃 Creating database dump…"
wp db export database-dump.sql --quiet
mv database-dump.sql $src
# Migrate Database
echo "🚚 Migrating database…"
cd $dest
wp db import database-dump.sql --quiet
rm database-dump.sql
wp search-replace $srcUrl $destUrl
# Migrate Media Library
echo "🌋 Migrating media library…"
rm -r $dest/wp-content/uploads/
cp -ar $src/uploads/* $dest/wp-content/uploads/
echo "🏝 Sync successful."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment