Created
June 14, 2025 13:57
-
-
Save kalebheitzman/f80cb44e0e7ccc04f8b8ad289c8535a6 to your computer and use it in GitHub Desktop.
sync-wordpress.sh
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
#!/bin/bash | |
# Configurable variables | |
REMOTE_SSH="[email protected]" | |
REMOTE_PATH="/var/www/yourproductiondir" | |
LOCAL_PATH="/Users/youruser/Sites/yourlocaldir" | |
REMOTE_URL="https://yourproductiondomain.com" | |
LOCAL_URL="http://yourlocaldev.local" | |
# Step 1: Sync files from production (wp-content only, for faster sync) | |
echo "π‘ Syncing wp-content via rsync..." | |
rsync -avz --info=progress2 \ | |
"$REMOTE_SSH:$REMOTE_PATH/wp-content/" \ | |
"$LOCAL_PATH/wp-content/" | |
# Step 2: Export database from production via SSH | |
echo "π‘ Exporting database from remote..." | |
ssh $REMOTE_SSH "cd $REMOTE_PATH && wp db export /tmp/prod.sql --quiet && echo 'β DB exported to /tmp/prod.sql'" | |
# Step 3: Download the exported DB | |
echo "π‘ Downloading database file..." | |
scp "$REMOTE_SSH:/tmp/prod.sql" ./prod.sql | |
# Step 4: Import DB locally | |
echo "π‘ Importing DB locally..." | |
cd "$LOCAL_PATH" | |
wp db import ../../prod.sql | |
wp search-replace "$REMOTE_URL" "$LOCAL_URL" --skip-columns=guid | |
# Step 5: Cleanup | |
echo "π§Ή Cleaning up..." | |
ssh $REMOTE_SSH "rm /tmp/prod.sql" | |
rm ../../prod.sql | |
echo "β Sync complete!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment