Skip to main content
  1. All Posts/

WP-Sync

Tools Open Source Sync WordPress
This is a bash script I wrote that copies WordPress dir and WordPress database between production, developer, local and remote environments.

It supports transferring directions as follows:

Local Prod  <--> Remote Prod
Local Prod  <--> Remote Dev
Local Prod <--> Local Dev
Local Dev <--> Remote Prod
Local Dev <--> Remote Dev
Remote Prod <--> Remote Dev

Usage:
1. Update your site domain name in the script; 
2. Place the script in your ~home dir on the local server;
3. Make sure to give it executive permission 

chmod +x wp-sync.sh

4. Run the script when you need to upload an updated site 

./wp-sync.sh

For example, I run an exact copy of my production server on my local VirtualBox virtual machine.
My typical development cycle looks like this:

- Start VirtualBox and spin up my VM
- Log into my website https://localhost:8888/wp-admin
- Do some work on the site ...
- Upload local update to the production or dev server:

Log into my local server:
ssh admin@localhost -p2222
Start the script
./wp-sync.sh

Follow a prompt to choose a direction.

- Once the transfer is done, log into freshly updated site and run the search/replace for all occurrences of your domain name.

For example, for a case
localhost --> example.com
We need to do:
Find				        	  	Replace to
//localhost:8888		  		//example.com
//localhost:8888				//example.com
%2Flocalhost%3A8888		  	%2Fexample.com