Copy / Tarring Files that have changed in the last 14 days

I have a server whose files change over and over again.

We want to have a script or cron job that runs every 7 days and finds any php files that have been modified or created in the last 14 days and puts them in a tar or zip file on the server so it can be downloaded.

This command finds the correct files:

find . -name "*.php" -mtime -14 -print

      

What else do I need to do?

+3


source to share


2 answers


if your list of files from the output is correct, just pipe it to tar:

find . -name "*.php" -mtime -14 -print | xargs tar cvf backup.tar

      

You should check the tar options in man. You might need to use for example -p (keep permissions) just find useful options in person and use whatever you need.

and add it to cron, the easiest way, if your distribution supports it, is to put your script in:

/etc/cron.weekly

      

otherwise, you need to execute modront crontab:



crontab -e

      

and put a line there like:

0 3 * * 6 <user> <your script>

      

it runs the script at 3 o'clock every Saturday, the last script is the day of the week, 0 or 7 is Sunday.

person 5 crontab:

 field          allowed values
          -----          --------------
          minute         0-59
          hour           0-23
          day of month   1-31
          month          1-12 (or names, see below)
          day of week    0-7 (0 or 7  is  Sun,  or  use
          names)

      

+4


source


cron good.



You may need GNU tar -files-from; xargs is dangerous here. xargs is fine if you know that the number of files is always small, but if the list of files gets large, restarting the tar version of xargs will toast all but the last n files.

+5


source







All Articles