Find, compress and move to new location but maintain folder structure
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. |
try to get it to copy keeping the folder structure, not compressing, first. that will be the hard part. once you get that working where you are copying one file at a time, changing that to do compression will be easier.
|
Quote:
It may not be as impressive as bending find(1) into doing it with single line but it's a solution that you -- or that "next person" -- will be able to come back to in the future and understand how it works. Good luck... |
untested
Code:
#!/bin/bash I have already hinted at one problem. You should check the exit status of mkdir before going on to the gzip and move. If you don't you will end up with compressed files in the original location ( at least that is the plan, I havn't tested the script ) good luck |
All times are GMT -5. The time now is 10:53 AM. |