Operating System - HP-UX
1845903 Members
5058 Online
110250 Solutions
New Discussion

How to Tell tar to not to copy few dir's

 
Basheer_2
Trusted Contributor

How to Tell tar to not to copy few dir's

I have a dir

/APPDIR

under this dir there are many sub dir's and files goes down to 3 or 4 levels of dirs and files. Some of log dirs are LOGDIR ERRLOG TRLOG SCANLOG.
I don't want these dirs and files in them. How can I do this using tar.

I tried cpio and it works fine.

find /APPDIR -name "*" -print > temp1

egrep -v "/APPDIR/LOGDIR|/APPDIR/ERRLOG|/APPDIR/TRLOG|/APPDIR/SCANLOG" temp1 > cpio.lst

cat cpio.lst | cpio -ocBv > bakup.022103.cpio
4 REPLIES 4
Pete Randall
Outstanding Contributor

Re: How to Tell tar to not to copy few dir's

How about this:


tar cvf /dev/rmt/0m `cat cpio.lst`



Pete

Pete
Jeff Schussele
Honored Contributor

Re: How to Tell tar to not to copy few dir's

Hi Basheer,

Instead of plain old tar for this backup, you should use fbackup.
You can include (-i) whatever paths you wish or exclude (-e) paths.
Or you could define a graph file to include OR exclude whatever you wish & just reference it.
Has the extra added benefit that it can handle +2Gb files whereas tar cannot.
See man fbackup for further details.

Rgds,
Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!
Chris Vail
Honored Contributor

Re: How to Tell tar to not to copy few dir's

If any of the files are larger than 2GB, you'll have to use Gnu Tar. Elsewise, you can do it with:
for FILE in `find . -type d|grep -v DIR1|grep -v DIR2`
do
tar cvfr /tarfile $FILE
done

Shell scripting from the prompt is an art form and bloodsport.....



Chris
Frank Slootweg
Honored Contributor

Re: How to Tell tar to not to copy few dir's

Have a look at pax(1).

pax is a mix and match of cpio and tar. For example for your case, you can tell it to write in tar *format*, but still take the list of filenames from *standard input*, i.e. like cpio.

A simple *demonstration*:

find . | pax -w -d | tar tvf - 2>&1 | more

I.e. this shows that pax can read the filenames from standard input and writes in tar format (otherwise the "tar tvf -" would fail).

Note that "-d" is needed in order to archive directories, *not* their content.