I have LOTS of logs and I need to compress them in a weekly basis, this is, every Saturday. I manage to do a oneliner to do that, but I don't want to re-compress the files already compressed. For example:
ls myDir/
test1 test2 test3
At saturday of week 1 I will have:
ls myDir/
test1.bz2 test2.bz2 test3.bz2
On week 2, I would have:
ls myDir/
test1.bz2 test2.bz2 test3.bz2 newTest1 newTest2
At Saturday of week 2 I would like to have:
ls myDir/
test1.bz2 test2.bz2 test3.bz2 newTest1.bz2 newTest2.bz2
This is: the compressed files, but not re-compress the already compressed files
This is my crontab oneliner:
0 2 * * 6 find /myDir -name "log*" -ctime +7 -exec bzip2 -zv {} \;
This is:
Find all the log files, 7 days of older and compress them.
(could be obvious! but I'm a newbie)
This only compress the files. But don't know how to do the verification or how to avoid the situation I'm telling. If I try to run the command again it seems that the files compressed are not affected, but I'm not sure if this always will be. I don't want to mess the production server of the company!