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.
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..
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.
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.
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.