find multiple file types and tar

There are these ksh files and config files that are written and updated on a daily basis.

All I want to do is write a script that finds both these types of files and archive them on a daily basis, to help in restoring in times of system outages and so on. Particulary I'm interested in .ksh , .sql files and .ini files (config)

Please help with a correct procedure to locate these files in a directory and all it's sub-directories, all at the same time and archive them suitably using "tar".

if it's only one type of a file i see the solution as

find dirname -name *.ksh | xargs tar -rf tarfilename

i'm not sure how i can do it for all the file types simultaneoulsy, if at all that's a sensible idea.

any help is appreciated.

TIA,
sirisha

find . -name ".sql" -o -name ".ksh" -o -name "*.ini"

use '-o' to create an OR and then pipe to tar like you had above.

Thank you so much Dogday! just didn't strike me at the moment... :smiley: !

But there's a minor correction.. your expression won't work unless the combined saerch pattern is enclosed within parantheses... otherwise the output would only contain the names of files with extension *.ini..

the actual expression is:

find . \( -name ".ksh" -o -name ".sql" -o -name "*.ini" \) ...

or else we get only files ending in .ini as the output.

Cheers,
Sirisha

Well perhaps your shell makes the difference. It works fine for me but I think the parenthesis appears more proper.

More help pls!!!

Infact, the expression worked fine, but what puzzles me now is the following tar

This is my shell script...

Archive=`(date +%Y%m%d)`
if [ -d searchdir ]
then
find searchdir -type f \( -name \\.ksh -o -name \\.sql -o -name \*\.ini \) | xargs tar -rf $Archive.tar
else
echo "searchdir is not a dir"
fi

The objective is to search for these file types on a daily basis and archive them into a tar file named with the corresponding date.

Any clues of where I'm mistaken?!

Regards
Sirisha

sorry.. i didn't explain my problem up there..

the error is " 20060224.tar: No such file or directory exists"

If i change the option of tar to -cf then the tar will be created but it is either empty (the searchdir has non-zero files of the desired extensions) or is non extractable, or even sometimes says "tar: Missing filenames"

if at all if the tar is created, i use tar -xvf 20060224.tar and see nothing!!

Getting back to the basics now..

I think i'm even wrong with my search pattern.. the expression doesnt just search for the required file types but includes all files in the directory along with the desired ones. :confused:

Can anyone Please suggest an answer?!

Despo for help,
TIA again!!

perhaps all you need to do is change the order of the commands.

Try:

tar -cf archive.tar `find . -name somefile`

DogDay has the right idea, but a redirection character is need in his expression:

tar -cf archive.tar < `find . -name somefile`

This way the output of the find command supplies tar with files name to act upon/tar.

Best regards

I don't need the redirect. Tar gets its input from find's STDOUT. The redirection you add generates an error. But your system may be different. I'm working on AIX using KSH.