CRON
L
Leichter Jr, Leo D. (CONTR) <leo.leichter@netl.doe.gov>
Fri 8/23/2019 12:12 PM
Inbox
To:
dleichter@hotmail.com;
Find, compress and move to new location but maintain folder structure
Was presented with something and I've kind of got it working but not completely and needing some help on the final part.
I have a folder structure /some/folder/structure/
Now after /structure/ there are more 12 sub-folders. Now each of these sub-folders contains in some instances many more sub-folders.
These are storing log files that are being collected from other systems.
Now I want to compress these log files after a number of days and then move them to an archive directory but I want to maintain this folder structure.
So I have a new archive area /new/archive/area/ and I have replicated the existing folder structure from /some/folder/structure/ to /new/archive/area/
I have a cron job that runs nightly to handle this compression/move.
Currently I have
echo "Beginning log compressions 'date +%Y-%m-%d:%H:%M:%S'"
cd /some/folder/structure/
find . / -type f -name "*.log" -mtime +5 -print -exe gzip -f {} \: -exec mv {}.gz /new/archive/area/\;
echo "End log compressions 'date +%Y-%m-%d:%H:%M:%S'"
But this is doing exactly what I feared it would and it's only creating these zipped files at the root of /new/archive/area/ instead of the adding these newly compressed files to the folder structure of each sub-folder.
Any help would be appreciated, thanks in advance.