Operating System - HP-UX
1855728 Members
5820 Online
104103 Solutions
New Discussion

Re: Script help required - calling the guru's

 
SOLVED
Go to solution
Simon R Wootton
Regular Advisor

Script help required - calling the guru's

Hopefully nothing too complex.

I have a directory containing many thousands of small files. Each day, about 20,000 files are added to this directory. Each night, a cron task runs to delete the files in this directory that are over 7 days old.

Instead of deleting the files, I need to archive them, but I'm concious of inode limits within filesystems.

Therefore, I'm looking for a script that will take the 20,000 or so files from one day, compress them into 1 file (using gzip?) and name that file as the date being compressed (eg. 140704.Z)

Anyone fancy a crack ??

Help will be rewarded generously!

Regards
Simon
5 REPLIES 5
Geoff Wild
Honored Contributor
Solution

Re: Script help required - calling the guru's

How about something like:

find /20000directory -mtime +7 -print >/tmp/filelist

TARFILE=`/bin/date +%y%m%d%H%M%S`.tar
FILES=`cat /tmp/filelist`

tar cvf /archdir/$TARFILE $FILES

gzip /20000directory/$TARFILE



Rgds...Geoff

Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
harry d brown jr
Honored Contributor

Re: Script help required - calling the guru's


Modify your script to use GNU's tar (http://hpux.cs.utah.edu/hppd/hpux/Gnu/tar-1.14/).

When using GNU's tar, use the --gzip. Once you have archived the file, delete it.

live free or die
harry
Live Free or Die
Steve Steel
Honored Contributor

Re: Script help required - calling the guru's

Hi

find dir -mtime +7|xargs shar|gzip > $(/bin/date +%y%m%d%H%M%S).gz

Puts them in a compressed shared archive

Then remove them

Steve steel
If you want truly to understand something, try to change it. (Kurt Lewin)
Kenneth Platz
Esteemed Contributor

Re: Script help required - calling the guru's

One-liner:

find /mydir -mtime +7 | tar cvf - | gzip > /mydir/$(date +%d%m%y).tar.gz

Enjoy :-)
I think, therefore I am... I think!
Kenneth Platz
Esteemed Contributor

Re: Script help required - calling the guru's

Correction. That should be:

tar cvf - $( find /mydir -mtime +7 ) | gzip > /mydir/$( date +%d%m%y ).tar.gz
I think, therefore I am... I think!