Skip to content

Instantly share code, notes, and snippets.

@santerref santerref/sync.sh
Last active Oct 1, 2019

Embed
What would you like to do?
Simple bash script to synchronize your WordPress dev (local) with your staging or production.
#/bin/bash
REMOTE_URL="https://staging.example.com"
LOCAL_URL="http://example.dev"
REMOTE_PATH="/home/staging_example/public_html"
LOCAL_PATH="/var/www/example.dev"
SSH_HOST="user@staging.example.com"
GREEN="\033[0;32m"
RESET="\033[0m"
BOLD="$(tput bold)"
echo -e "$GREEN$BOLD(1/6)$RESET Exporting WordPress database."
wp --quiet --path=$LOCAL_PATH db export ~/wordpress.sql
echo -e "$GREEN$BOLD(2/6)$RESET Rsyncing uploads and plugins folders."
rsync -qavz -e "ssh -q -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" "$LOCAL_PATH/wp-content/uploads/" $SSH_HOST:$REMOTE_PATH/wp-content/uploads/
rsync -qavz -e "ssh -q -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" "$LOCAL_PATH/wp-content/plugins/" $SSH_HOST:$REMOTE_PATH/wp-content/plugins/
echo -e "$GREEN$BOLD(3/6)$RESET Uploading wordpress.sql database export."
scp -q ~/wordpress.sql $SSH_HOST:/tmp
echo -e "$GREEN$BOLD(4/6)$RESET Importing wordpress.sql database into remote host."
wp --quiet --ssh=$SSH_HOST$REMOTE_PATH db import /tmp/wordpress.sql
echo -e "$GREEN$BOLD(5/6)$RESET Running wp search-replace on remote host."
wp --quiet --ssh=$SSH_HOST$REMOTE_PATH search-replace "$LOCAL_URL" "$REMOTE_URL"
echo -e "$GREEN$BOLD(6/6)$RESET Cleaning files."
rm -f ~/wordpress.sql
ssh -q $SSH_HOST /bin/bash << EOF
rm -f /tmp/wordpress.sql
EOF
@dotob

This comment has been minimized.

Copy link

dotob commented Aug 25, 2018

what is the wp script?

@TimLamoureux

This comment has been minimized.

Copy link

TimLamoureux commented Oct 28, 2018

It is the WP-CLI script

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.