Running Ubuntu 12.04, I work software "production" on certain folders and then I usually copy files I make up to another paths where I do the "deployment".

For example, sometimes I produce some files in /home/user/develop and I want them to go to /media/ntfs too. Also, for example I work on /home/user/develop but I want them to go to /var/www if I'm testing web stuffs.

So, any last generated folders, or any given files list should be copied.

I thought first this was about symbolic links but I think it isn't what's the best way to do this, scripting?

  • What exactly do you need to copy? Is it a specific list of file names? The N most recently created files? All executables? – terdon Aug 21 '13 at 22:48
  • Dunno about mirroring "changes", but if you want to mirror state of one folder in another, another alternative is something like bindfs, with the advantage that you can setup permissions for the mirror side. – Luis Machuca Aug 21 '13 at 22:51
  • 1
    If you are planning to automate this for production it sounds like a recipe for disaster. – Daniël W. Crompton Aug 21 '13 at 22:58
  • 1
    Why @DaniëlW.Crompton? – diegoaguilar Aug 21 '13 at 23:00
  • 1
    If it is automatically you will be deploying code which is not production ready. – Daniël W. Crompton Aug 21 '13 at 23:03

rsync syncs stuff between directories and even different servers. It has includes/excludes support, etc. If you want stuff to be really synchronized automatically, then, you could run rsync with whatever parameters needed.

You can put the command and all its parameters in a script, and then...

You can run that script in a scheduled job if you want it to do the copy at a given interval, or you can run the script manually when a sync needs to happen, and finally, you can listen on to filesystem events on your relevant directory, using inotify, to run rsync when certain changes happen in the directory.

You can do that either by a while loop that blocks on inotify, or by using special programs/scripts designed to do stuff like that, for example:

rsync-inotify: http://code.google.com/p/rsync-inotify/

lsyncd: http://code.google.com/p/lsyncd/

and so on...

  • I was going to say rsync, but I wouldn't have a scheduled job, he could bring down production if he's busy editing something critical. – Daniël W. Crompton Aug 21 '13 at 23:05
  • 2
    Well, I left the option to him to decide how to execute the actual copy operation... :) Personally, I would think the correct way would be to commit to some source control, and then checkout a revision to a staging environment, then, if successful, checkout the same revision to production. But that wasn't his question :-) – Shimi Aug 21 '13 at 23:06
  • I agree with your last comment as it, @DaniëlW.Crompton. Just as I wrote in question your comment seems obvius, and the @Shimi alternative is also great. I would consider this points, because I agree copying everything would be naive or immature. However for general usues, I'll check out rsync cause it seems to be effective. – diegoaguilar Aug 21 '13 at 23:08

You can replicate a directory to another directory with rsync. Rsync doesn't copy files that are already in the target directory with the same content (or more precisely, with the same date and size).

rsync -a /home/user/develop/ /var/www/

Updating the live server in real time isn't a good idea: if you're in the middle of a change and the files aren't in a working state, you don't want to deploy them. Note that propagation with rsync isn't instantaneous either, so there will be a small window of time during which some of the new files are in place but some of the old files are still present.

Revision control would solve this and also help you in other ways. When you've made changes, commit them. In the live server, do an update (or fetch or whatever your revision control software calls it). Revision control maintains a history of changes and allows you to track changes across multiple systems.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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