Last active
May 9, 2018 13:42
-
-
Save chrisgrabinski/e3dede75a9c57f9dfc75be042538a134 to your computer and use it in GitHub Desktop.
Sync database and media library between two WordPress installations with WP CLI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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