Monday, November 14, 2011

local rsync to sync directories under different users

    In my current project, all developers have their own userids for the source control and a common user(appuser) for checking out and running the application on staging and production machines.
  
    For a developer who needs to code and test the app on his machine; needs to sync (check out and update) the code twice - one with his userid(raghu) for development and the other with the appuser for running the applicaiton.
 
    Switching between users was a pain, so I was thinking of an alternative, where I do not have to sync the same code twice. Thats when rsync came as the rescuer.

    Solution:
  • dev(raghu) user needs to checkout the code under a directory(app) inside his home(/home/raghu)
  • appuser needs to be part of the dev(raghu) group(usermod -G raghu appuser)
  • dev(raghu) user needs to grant read and execute privilege for the dev(raghu) group (chmod g+rx /home/raghu) on the home directory (/home/raghu).
  • an rsync process needs to be run as cron to sync the /home/raghu/app directory with /home/appuser
  # cron to keep files in /home/raghu/app/ and /home/appuser in sync 
  0 11 * * * cd /home/appuser; rsync -avz --no-g --no-o --exclude=CVS /home/raghu/app/ .
The cron above is set for the appuser. It runs daily at 11 am. The rsync is run in archive(-a) mode with the symbolic links, devices, owners, groups and permissions preserved in transfer. In my case, I don't need the owner and group to be preserved. This can be done by (--no-g and --no-o). The --exclude option can be used to exclude directories that shoud not be sync'd. In my case it omits all files under the CVS meta directory.


No comments:

Post a Comment