How do I create a cron job to copy all files that are new within the 1 day span (each day at midnight)? So essentially all files created from the day of to the new folder with all permissions, date attributes, owner/group, in tact.
All files from /var/www/folder1/ to /var/www/folder2/
using crontab -e
Essentially, I am looking for the parameters that can be used to copy files daily from one folder to the other keeping all attributes intact.
Linux: UBUNTU 10.04 lts
cron only executes commands at a given time. In order to do what you want, you need to figure out a command that will do what you want, and then execute it with cron at a given time.
For example, to simply copy the files from one location to another, you could use
rsync -a /origin /destination
and then schedule it to run with cron by running
crontab -e
and specifyingin the file. That will cause your rsync to run at midnight each day.
Doing that each day will keep the two directories in sync. If you want to only copy files that have been created in the last day, that's a bit more difficult, but can be done with
find
with the --newer and -exec option to run acp
to copy the files.So, something like this, bear in mind this is find on linux [find . -ctime 1 -print | xargs] will get you files dated within last day, basically 1*24hrs. You can do as you please with this filelist. Of course, rsync is a way to go, as suggested earlier. That's what rsync is for, maintaining mirrored directory structures.