How to use rsync for production release automation

Rsync can be used to automate the production releases for wordpress or any other site. I maintain two wordpress sites – one for development purpose and one for production. Both sites have their respective apache web server document root. I have used the convection devel_infoheap and prod_infoheap for the two blogs.

Here is a workflow which works nicely for me:

  1. Keep all your stuff (non wordpress) under version control.
  2. Create a bash script which take an argument “devel” or “prod”. You can keep any other ids for your develment and production sites.
  3. Keep this code in your sync script
    DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" pwd )"
    if [ "$1" == "prod" ] ; then
    #change it if you target machine is not same as the script machine
    cd $DIR
    ## replace files/directories to sync and the target directory according to your configuration
    rsync -r -az ../ui/data ../ui/img $HOST:/var/www/${CONFIG}infoheap/
  4. You can add more files and directories to above script as and when needed.
  5. For pushing to devel blog site just run devel and for production just run prod. This make push process very streamlined.
  6. For files like robots.txt I maintain two versions (devel_robots.txt and prod_robots.txt). With above convection, it is easier to sync robots.txt also using the following code in bash script
    rsync -r -az ${CONFIG}robots.txt  $HOST:/var/www/${CONFIG}infoheap/robots.txt

    Note that since source and target file names are different here, we had to specify target file in rsync command.

Share this article: share on Google+ share on facebook share on linkedin tweet this submit to reddit


Click here to write/view comments