Operating System - HP-UX
1819931 Members
3098 Online
109607 Solutions
New Discussion юеВ

how to tar files in a directory exclude those in a sub_dir to a tape ?

 
SOLVED
Go to solution
faust2004
Regular Advisor

how to tar files in a directory exclude those in a sub_dir to a tape ?

Hi, friend,
I want to tar files in /opt to tape, but exlude those in /opt/test .


Thanks
Sunny
8 REPLIES 8
Rajeev  Shukla
Honored Contributor

Re: how to tar files in a directory exclude those in a sub_dir to a tape ?

I dont think you can excude using tar. Why dont you use fbackup.
run fbackup with -i /opt and -e /opt/test option. Do a man on fbackup and you'll see you can create a graph file and specify that graph file with -g option.

Rajeev
Michael Tully
Honored Contributor

Re: how to tar files in a directory exclude those in a sub_dir to a tape ?

Hi,

You'll be out of luck trying to use 'tar' and excluding directories properly. You will only be able to backup the other directories using this example.

tar cv -C /opt/perf . -C /opt/dce
etc for each directory

Your best bet is to use 'fbackup', to me it a rather easy.

e.g. To backup all of /opt and exclude /opt/test

# /usr/sbin/fbackup -i /opt -e /opt/test -f /dev/rmt/0m

The man page gives some interesting infomation and examples.

HTH
Michael
Anyone for a Mutiny ?
faust2004
Regular Advisor

Re: how to tar files in a directory exclude those in a sub_dir to a tape ?

Hi, Michael ,

But i have to use tar. and I wish to tar
all these file under /opt, include files, directory.

Thanks
Sunny

S.K. Chan
Honored Contributor
Solution

Re: how to tar files in a directory exclude those in a sub_dir to a tape ?

You have 2 options ..
1) Get gnu tar at
http://hpux.cs.utah.edu/hppd/hpux/Gnu/tar-1.13.25/
which has the exclude option

OR

2) You can capture the listing of all the directories under /opt in a file, delete "/opt/test" dir in that file and then run your tar against that file. For example ..
the file "mylist" has these entries ..
/opt/apps
/opt/OV
/opt/ansic
...
You can then run your tar like so ..

# cd /
# tar cvf /dev/rmt/0m $(cat mylist)

assuming tape device is /dev/rmt/0m.
Michael Tully
Honored Contributor

Re: how to tar files in a directory exclude those in a sub_dir to a tape ?

Hi,

You'll have to use GNU tar. Here's the link. This script should also help.

http://hpux.connect.org.uk/hppd/hpux/Gnu/tar-1.13.25/

=================================
#!/sbin/sh
list=""
for i in `find $1 -type f`
do
grep -q "^${i}$" /etc/tar.exclude || list="$list $i"
done
echo tar cvf /dev/rmt/0m $list
=================================

Michael
(script courtesy of Robin Wakefield)

Anyone for a Mutiny ?
Frank Slootweg
Honored Contributor

Re: how to tar files in a directory exclude those in a sub_dir to a tape ?

As an alternative (to GNU tar) you could use the pax(1) command. pax is like cpio, in that it can read a list of files from standard input, but (also) like tar, in that it can write in tar format.

So you generate a list of the wanted files and pipe that to "pax -w". I.e. in your case probably something like:

find /opt | grep -v '^/opt/test' | pax -w -vd

note that the "d" option, only archive directories not their contents, is needed because find(1) already lists the contents of the directories.



Chris Vail
Honored Contributor

Re: how to tar files in a directory exclude those in a sub_dir to a tape ?

A kludgey solution would be to create a text file with the filenames that you do want. Do this with a simple script. This should work with any version of unix or tar.

!#/bin/ksh
cd /opt
for FILE in `ls -1|grep -v test`
do
echo "/opt/$FILE">>/tmp/somefile
done
tar cvf /dev/tapedevice `cat /tmp/somefile`
rm /tmp/somefile


Good Luck
Chris
q tang
Occasional Contributor

Re: how to tar files in a directory exclude those in a sub_dir to a tape ?

Hi Sunny:

I think u can do it as following:

tar cvf tarfilename `find /opt -type f | grep -v "/opt/test/"`

Good lucky!

Tang qiang
08/01/03