cleanup - cleanup files in a directory based on the time of last access



Usage:

cleanup
-a|-t  accessTime directoryToClean archiveDirectory [exceptionFile]



-a: process the files (archive)

-t: test - display a list of what would happen

accessTime: files that haven't been accessed in accessTime days are candidates to get archived

directoryToClean: directory containing files to clean, all files in that directory and in all directories below will be processed

archiveDirectory: archived files will be moved here and compressed

exceptionFile: optional argument, contains patterns that are used to bypass files


Examples:

    #show what would be done to files in SAVEDLISTS that haven't
    #been accessed in 30 days or more
        cd /datatel/live/collive
    cleanup -t 30 SAVEDLISTS /usr/local/archivedSavedlists


  #Archive all files in SAVEDLISTS that haven;t been accessed in 30 days
     #If today is June 30th, files will be archived in /usr/local/archive/0630, where they will live until removed
     #or the next year that files are archived to the same date
         cd
/datatel/live/collive
    cleanup -a 30 SAVEDLISTS /usr/local/archivedSavedlists

  
  #Use an exception file
    cd /datatel/live/collive
   
cleanup -a 30 SAVEDLISTS /usr/local/archivedSavedlists \ /usr/local/archivedSavedlists/exceptions


  #The exception file - ignore files that start with AR, have the word KEEP in them, or end with .SAVE
    # The ^ means "beginning of line"
    #A word (e.g. KEEP) by itself means "any filename containing KEEP"
    #.SAVE[0-9] means "ending in .SAVE, followed by one or more numbers (SAVEDLISTS are appended with 3 numbers)

    ^AR
  KEEP
  .SAVE[0-9]+

Setup:

All you should have to do to set this up is to create the directory that you'll use to archive the files - periodically, you will probably want to clean out this directory.
You can set up exception files for different circumstances  - for instance, if you have a directory where:

Files appended with SAVE30 are saved for 30 days, files appended with SAVE60 are saved for 60 days, files appended with SAVE120 are saved 120 days:

Delete everything not used in the last 120 days:
cleanup -a 120 SAVEDLISTS /usr/local/archivedSavedlists


except.SAVE60 file:

SAVE120[0-9]+

Delete everything not used in the last 60 days except for files ending in SAVE120:

cleanup -a 60 SAVEDLISTS /usr/local/archivedSavedlists except.SAVE60

except.SAVE30 file:

SAVE120[0-9]+
SAVE30[0-9]+

Archive everything not used in the last 30 days, unless it ends with SAVE60 or SAVE120:

cleanup -a 30 SAVEDLISTS /usr/local/archivedSavedlists except.SAVE30