Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm still kind of new to Linux, but here's what I'm trying to do.

I need to copy all subdirectories and files from one directory to another ever 5 minutes or so, with the old data automatically being overwritten with the new data.

I'd also like this to run at startup. Is there any way this can be done? If so, what program would I need to schedule the automation and what is the command line I would need.

share|improve this question
    
Also because it makes the site work better (that's the real reason..) –  intuited Jun 11 '10 at 15:55

2 Answers 2

up vote 5 down vote accepted

I would do the actual copy with

rsync --archive --delete "fromdir/" "todir/"

This is going to be more efficient than using cp, since rsync only copies files that have changed, and even then only copies over the change itself, rather than the entire file.

If you prefer that it not delete files in todir that have been deleted in fromdir, you just leave out the --delete option.

The --archive option basically tells it to preserve the state of the files as well as their content. Note that if you have any symbolic links in dir1, this will copy the links themselves, and not the files they link to. Using this flag with rsync is similar to using cp -a.

Make sure you use the closing slash on fromdir/: this tells rsync to copy the contents of that directory, rather than the directory itself. In other words, if you leave out the final /, you will end up with

todir/
todir/stuff
todir/fromdir/
todir/fromdir/morestuff

rather than

todir/
todir/morestuff
share|improve this answer
    
+1 for improving my answer! –  BloodPhilia Jun 11 '10 at 8:00
    
+1 for cooperation! Actually I can't, I already voted your answer up at the beginning. –  intuited Jun 11 '10 at 15:54

You need to put a script in cron, how to do this, read here: http://www.foogazi.com/2006/12/07/understand-cron-jobs-in-5-minutes/

Instead of a script, you could type a command to execute in your crontab, it would look like:

*/5 * * * * cp -r /fromdir /todir

also add to /etc/crontab the following line to exexute it at boot:

@reboot root cp -r /fromdir /todir
share|improve this answer

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.