Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have to keep copying files over from my ~/src to /home/httpd directory, which is a pain when I'm making front end changes. Is there a way I can have changed files sync automagically? -- and specifically only while I'm developing -- something I can turn on and off.

share|improve this question
add comment

3 Answers 3

up vote 2 down vote accepted

Although not automatic, once you are done doing modifications, use rsync:

$ rsync -r --delete /home/username/src/ /home/httpd

You could even create an alias:

$ alias sync='rsync -r --delete /home/username/src/ /home/httpd'

As I emphasize to everyone, before using this you should check out man rsync for additional options.

Also, I'd strongly suggest version control (svn or git perhaps) for a multitude of reasons.


Edit:

What I would personally do is use a bash loop---specifically while loop with a sleep. Enter the following in the shell:

while true; do 
    sleep 300 # Every 5 minutes
    rsync -r --delete /home/username/src/ /home/httpd
done &

This will make it a background job that you could kill at anytime. Just type jobs to see the index of the job and, when you do not need it anymore, type kill %(index).

Alternatively, to add the command as a cron job for, e.g., every 10 minutes, append the following to your crontab:

*/10 * * * * rsync -r --delete /home/username/src/ /home/httpd

To edit your crontab:

$ crontab -e
share|improve this answer
    
rsync is cool but how to do this automatically, maybe with cron? +1 –  qodeninja Dec 6 '11 at 16:41
add comment

I am not entirely sure what your objective is, but a few suggestions that might be of some use:

Instant, on modification (save): If you want the files to be updated as soon as one is modified, I might ask why you don't just make your changes in /home/httpd and then once everything is to your satisfaction copy them back. The idea of a working directory for safeguards (or to prevent taking down your site with a bad edit) is negated if the changes are to be copied immediately.

Near-instant, on modification: If for some reason, you wish to have your changes applied nearly instantly, on file modification (i.e. as soon as a file is saved, it gets copied over) then I would suggest looking into incron. It can be set to trigger a script when a directory changes.

On demand (not instant):

If you are looking to complete all your edits and then push the changes (which is what I expect you are looking for), then you have several options. I presume that the annoyance lies in determining what files were changed, and copying them from a variety of different directories.

Shell script: One simple solution to this is to use rsync. It will determine what the changes are in your ~/src directory relative to your /home/httpd directory, and make the changes needed to get your /home/httpd in sync with your source directory.

Version Control: The most effective solution, although, considerably more complex than rsync, is version control - for instance, Subversion. Basically:

  • Create a repository on your server
  • Import your files into the respository
  • Check out a working copy to /home/httpd
  • Setup a post-commit hook that will update /home/httpd
  • Check out a working copy to ~/src
  • Make your changes and commit them to the repository (svn commit) - the hook will automatically update /home/httpd

While more difficult to setup, initially, this approach allows the greatest control, and will easily let you rollback changes, list the modified files, and see what changes (diffs) were made at each revision - you can also add a description to your changes with each commit.

share|improve this answer
    
Upvote for version control option that contains a post-commit hook –  ckliborn Dec 6 '11 at 3:49
    
to your first point -- the issue is the code gets built and deployed into httpd and the structure isnt the same from ~/src to httpd -- but I'm only changing front end files which dont require a rebuild or a restart of apache --- and /home/httpd isnt versioned. The issue is getting my front end changes copied over to an application that has already been built and packaged and is deployed. So far the incron seems more like what I am looking for. +1 for the thoughtfulness of your answer. thank you –  qodeninja Dec 6 '11 at 16:40
add comment

Look at lsyncd. It uses inotify to get info about changes in files and sync them over rsync.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.