I want the script to daily archive only new files from the directory (in this folder, new or changed files from the remote server will be backed up daily).

How can I get the date of the last modified (new) files in the directory in the script?

  • via find -mtime - Nofate
  • 2
    + every time you call the script, save the time of the call to some kind of daddy and then look for all that is more - jmu

1 answer 1

I would suggest focusing on some kind of “flag” file that will be updated every time after archiving: everything that will be newer than this file will need to be archived next time.

once create such a file (with an arbitrary name):

 $ touch flag.file 

and then the find program find everything that is newer than this file (the -mindepth 1 option -mindepth 1 needed so that the link does not include the directory in which you run this command):

 $ find -mindepth 1 -newer flag.file 

The output of this command can be (for example, using xargs ) passed as a list of files to the tar program:

 $ find -mindepth 1 -newer flag.file | xargs tar -czf /путь/к/создаваемому/архиву 

do not forget to update the “flag” file after creating the archive:

 $ touch flag.file