0

I am very new to bash scripting, so bear with me, please. I need to collect, compress and delete files in the archive directory of a directory tree older than 30 days old for each respective folder. The directory structure looks like this ...

root
-export
--client01
---archive
-process
--client01
---834
----archive
---835
----archive
---837
----archive

In each archive folder I need to create timestamped tar/zip with files 30 days or older in the tar/zip file before I delete them (i.e., 20190730_111543.zip)

Hope this makes sense.

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
  • It's not quite clear to me what each respective folder encompasses, is that just the numbered directories under --client01? – tink Jul 30 '19 at 17:52
  • each respective folder = each archive folder. So, in the archive folder under process/client01/834 the script should go into the folder, find files 30 days and older, compress them into a zip/tar and then delete the files (leaving just the compressed file). – Lucas Davenport Jul 30 '19 at 18:01
  • Does that include the already present archives? What are the criteria there? – tink Jul 30 '19 at 18:11
  • @LucasDavenport have you seen this? https://unix.stackexchange.com/questions/102752/remove-all-files-created-before-a-certain-date/102767#102767 Also you might want to use tree dirname to show the tree structure of the named directory – Valentin Bajrami Jul 30 '19 at 20:10
  • so far, I've come up with the following code, but it doesn't traverse through the directories as I expected - it only creates an tar.gz in one folder . . .name=$(date '+%Y%m%d')

    for dir in $(find . -type d -iname 'archive'); do cd $dir find . -type f ! -iname '*.tar.gz' -mtime +28 | tar -czvf "$(date '+%Y%m%d_%H%M%S').tar.gz" --null -T -; done

    – Lucas Davenport Aug 05 '19 at 14:11

0 Answers0