WordPress Push and Pull

I seem to be doing a lot of Dev Op stuff lately and recently needed to quickly deploy a local site I was developing. I thought there would be a simple way of doing this with VVV or some other third-party script but unfortunately I did not find a solution that suited my needs, so I made one. Eventually I will either move to Capistrano or expand on these scripts to accommodate different environments and use cases but for now this is working for me.

Prerequisites

To use these scripts you’ll need a UNIX based OS, Vagrant and an existing WordPress site on your remote server to sync with.

Installation

For quick install I have these scripts on Github as Gists, they can be installed by pasting the following line in your terminal:

WP-PULL

git clone [email protected]:27a1c1466bb923177740.git ~/tmp/wp-pull && mv ~/tmp/wp-pull/wp-pull ~/bin/wp-pull && rm -rf ~/tmp/wp-pull && sudo chmod +x ~/bin/wp-pull

WP-PUSH

git clone [email protected]:b882c02398d669741b94.git ~/tmp/wp-push && mv ~/tmp/wp-push/wp-push ~/bin/wp-push && rm -rf ~/tmp/wp-push && sudo chmod +x ~/bin/wp-push

The above will clone the gist repo, copy the file to your ~/bin, remove the cloned repo and modify the permissions so the file can be executed.

WP-PULL

This is a quick way to pull files and data from a remote server to sync your local WordPress site to the remote. WP-PULL starts by collecting information from the remote and local instances of the site you want to sync. It asks for a few simple variables like HOSTNAME and USERNAME then checks that the same USERNAME exists locally, it doesn’t it asks the name it should map to. Then the fun begins. The database is exported from the remote and all files are rsynced from the remote to the local instance. The database is then imported and the script finishes with some basic cleanup like search and replace on database to convert remote url to local url and the DB backup is removed.

WP-PUSH

WP-PUSH does similar things to WP-PULL but in reverse. In this script we are doing the same checks but will be replacing the remote database and files with the local version’s.

Warning: This is script is not meant to replace standard deployments. You should always use best practice methods for pushing code and data, this is not one of them. This is a quick and dirty way to deploy a development site to a server.

Happy syncing and bye for now.

Leave a Reply

Your email address will not be published. Required fields are marked *