Exclude them in the find
command
time find . ! \( -name '*.log' -o -name '*.tmp' \) -print | cpio -o | gzip > $DUMP_DIR/$f2.cpio.gz &
You can keep adding -o *.suffix
to the list.
Question
I have a shell script that runs on AIX 7.1 and the purpose of it is to archive a bunch of different directories using CPIO.
We pass in the directories to be archived to CPIO from a flat file called synclive_cpio.list.
Here is a snippet of the script..
#!/bin/ksh
CPIO_LIST="$BASE/synclive_cpio.list"
DUMP_DIR=/usr4/sync_stage
LOG_FILE=/tmp/synclive.log
run_cpio()
{
while LINE=: read -r f1 f2
do
sleep 1
cd $f1
echo "Sending CPIO processing for $f1 to background." >> $LOG_FILE
time find . -print | cpio -o | gzip > $DUMP_DIR/$f2.cpio.gz &
done <"$CPIO_LIST"
wait
}
Here is what we have in the synclive.cpio.list file...
/usr2/devel_config usr2_devel_config
/usr/local usr_local
/usr1/config usr1_config
/usr1/releases usr1_releases
When the CPIO is running, it will archive everything in the passed directory.. what I would like to do is try to exclude a few file extension types such as *.log and *.tmp as we don't need to archive those.
Any idea how to change run_cpio() block to support this?
Thanks.
Solution
Exclude them in the find
command
time find . ! \( -name '*.log' -o -name '*.tmp' \) -print | cpio -o | gzip > $DUMP_DIR/$f2.cpio.gz &
You can keep adding -o *.suffix
to the list.
OTHER TIPS
Another method is to use egrep -v in the pipeline. I believe that would be a teeny tiny bit more efficient.
time find . -print | egrep -v '\.(tmp|log)$' | cpio -o | gz
To me, it is also easier to read and modify if the list gets really long.