Synchronizing using rsync

So I run quite a few wordpress blogs now and time and again I like playing around with a plugin or a theme and want to ensure that I first try it out locally and then push it to the production version. Also is hard for me keep track of what files I have changed or modified and really wouldnt want to drop the entire folder on the ftp client.
I had been thinking about a cleaner way to do it, one of the option was to push my files to SVN repo and then do a checkout on the production box. I should really be doing something like this now that I will be hacking my wordpress installations more than I have ever done but living dangerously right now, I decided to take the approach of syncing files using the good old rsync command. This post is really just to store the commands somewhere so that I can refer to it later. But in case you find it useful as well, then leave a comment.

So before I start, here are a couple of ways to get rsync locally depending on what you run as an operating system.

On Debian or Ubuntu Linux:

# apt-get install rsync

or

$ sudo apt-get install rsync

On RHEL (Red hat enterprise Linux (RHEL)

#up2date rsync

Or for yum based installation manager

yum install rsync

rsync command common options

  • –delete : delete files that don’t exist on sender (system)
  • -v : Verbose (try -vv for more detailed information)
  • -e “ssh options” : specify the ssh as remote shell
  • -a : archive mode
  • -r : recurse into directories
  • -z : compress file data

Synchronize a local directory with a remote directory

$ rsync -r -a -v -e "ssh -l luke" --delete busybox.enterprise-starship.foo:/webroot/ /local/webroot

Synchronize a remote directory with a local directory

$ rsync -r -a -v -e "ssh -l luke" --delete /local/webroot o busybox.enterprise-starship.foo:/webroot

Here’s the official documentation for rsync for more settings.
http://samba.anu.edu.au/rsync/documentation.html

About rp

Architect for large, highly scalable LAMP applications and Technical Manager with special focus on metrics based continuous improvement of teams and products. Rajat has close to a decade of experience of a very wide range of skills related to infrastructure, middleware, app servers all the way to front-end technologies and software development methodologies including agile, iterative waterfall, waterfall as well as ah-hoc startup using the right approach in the right context to reduce time to market.