Archive & delete files older than x days, maintaining the directory structure

Viewed 539

we have log files generating from different sources and storing in directories & sub-directories. The directory structure is something like below.

I want to tar & zip the file older than 30 days maintaining the directory structure and delete the archived files after the tar & zip.

Can someone help me with this? How this can be achieved.

dataload
├── apiConnectorApp
│   ├── csv
│   │   ├── 20210216231308
│   │   ├── batch1
│   │   ├── batch2
│   │   └── batch3
│   ├── day1Load
│   ├── logs
│   └── sql
├── configs
│   ├── eSite
│   │   ├── CKB2B
│   │   │   ├── CatalogEntryAssociations
│   │   │   ├── CatalogGroup
│   │   │   └── CatalogGroupCatalogEntryRelation
│   │   └── THB2B
│   │       ├── CatalogEntryAssociations
│   │       ├── CatalogGroup
│   │       └── CatalogGroupCatalogEntryRelation
1 Answers
find dataload -type f -mtime +30 -exec tar -rf archive.tar {} + -exec rm -f {} +

Run find with dataload as the parent directory. Process files that have been modified more that 30 days ago. Append as many files as possible (+) to an archive file "archive.tar" by using the tar -r flag. Then remove the files.

Related