Linux: Zipping up a group of files after X days

Associate
Joined
19 Jun 2003
Posts
1,680
Location
West Yorks, UK
Hi all,
I have an FTP directory in which files are continuously uploaded each day (say around 40 or so). They all have the same filename structure, e.g.:
Code:
dep1_20070228085845.csv

Basically, the first 4 characters group the files (there are "dep" and "par" files, with numbers from 1-3). The remaining characters after the underscore are the date and time the file was generated, in reverse format (so the example above is 28/02/2007 8:58:45am).

I want to have a cron task that runs every night to bunch any files that are 7 days or older into a .zip file for that date. So, i would end up with the following:
Code:
dep1_2007-02-28.zip
par2_2007-02-28.zip
dep1_2007-02-27.zip
etc etc....

How can I achieve this with standard Linux commands?

Cheers,
Matt
 
Hi,
Thanks very much for the reply. Unfortunately, i've been a bit thick. The files are actually Directories, with up to 4 files inside, e.g.
Code:
/archive
    /dep1_20070228134513/
         file1.txt
         file2.txt
         file3.txt
         file4.txt
    /dep2_20070228091241/
         file1.txt
         file2.txt
         file3.txt
         file4.txt
etc....

How does that affect the script?

Cheers,
Matt
 
Yeah, the find method seems to be a nice efficient way of doing things. I can run the following manually, and it works a treat:
Code:
find . -type d -name "dep1_20070116*" -print | zip -r -o -m -T dep1_20070116 -@
That will find appropriately named directories, pass the list to the zip function, which zip's them up recursively. The other parameters set the last modification date/time of the zip file (-o), delete the source files once zipped (-m), and checks the zip file integrity before finishing off (-T).

So, i've changed my process slightly. I'm going to have another script which moves the files to be zipped into an archive folder. I can then either do this manually, or just set it to move files older than 7 days in.

So the thing I need to work out now is how to substitute the filenames in the above command - i.e., how I can make the script look through a directory, find a group of folders (20070204* for example), and then use this filename for the zip filename?

Matt
 
Back
Top Bottom