Within a given directory in linux environment, I need to pick all files modified after a certain date (let's say 7 days) as well as all directories (only in root directory, hence non recursively) created after the same date.
After that, I have to take care of 3 directories which except the last given rule. For these, the process has to be recursive within each of them. In one of these directories, there's a file to be excluded no matter what.
Finally, I have to add all the objects matching these patterns to a single .tar archive. Every file/directory must of course keep full relative path within the .tar file (starting from base directory).
So let's assume we have:
myHome
|-- normalDir1 // older than 7 days
| |-- blah.txt
| |-- to_be_excluded_nmw.txt // should never be included anyways
| `-- poems.txt
|-- normalDir2 // created yesterday
| |-- blah2.txt /*
| |-- whatever2.txt * Since it's a normal directory,
| |-- whatever3.txt * I want to exclude these files from .tar
| `-- poems2.txt */
|-- exceptionDirectory1 // older than 7 days
| |-- actions // older than 7 days
| | `-- power.sh // older than 7 days
| `-- events // older than 7 days
| |-- deploy.php // older than 7 days
| `-- set.php // older than 7 days
|-- exceptionDirectory2 // older than 7 days
| |-- actions2
| | `-- power2.sh // created yesterday
| `-- events2 // older than 7 days
| |-- deploy2.php // created yesterday
| `-- set2.php // older than 7 days
|-- file_to_be_updated.php // created yesterday
`-- file_NOT_to_be_updated.php // older than 7 days
the resulting .tar should contain:
./normalDir2/
./exceptionDirectory2/actions2/power2.sh
./exceptionDirectory2/events2/deploy2.php
./file_to_be_updated.php
I've created this script:
#!/bin/bash
TODAY=`date --rfc-3339=date`
FILENAME=$TODAY-package.tar
find ./require ! -name db_connection.php ! -path ./require -mtime -7 -print | xargs tar cvf `date --rfc-3339=date`-package.tar
find ./img ! -path ./img -mtime -7 -print | xargs tar uvf `date --rfc-3339=date`-package.tar
find ./plugin ! -path ./plugin -mtime -7 -print | xargs tar uvf `date --rfc-3339=date`-package.tar
find . -maxdepth 1 ! -name $TODAY-package.tar.gz ! -path . -mtime -7 -print | xargs tar uvf `date --rfc-3339=date`-package.tar
but it doesn't seem to work properly as it quits almost immediately with this error:
tar: ./img: Impossibile open: Is a directory
Notice "require", "img" and "plugin" being the three special directories to be treated recursively. What's wrong with the script? Thank you for your assistance.
tar --after-date
?