Operating System - HP-UX
1819802 Members
3199 Online
109607 Solutions
New Discussion юеВ

tar: excluding files from an archive

 
Geoff Hartnell
Advisor

tar: excluding files from an archive

On Solaris the tar command has an option (X) to read a file containing a list of files to be excluded from a tar archive.

On the version of HP-UX that I am using (B.11.00 U 9000/800 ) there is no X option

I need to be able to create different archives from the same root, but to exclude different parts for different builds.

Does anyone know how to do this on HP-UX

Thanks
12 REPLIES 12
Steven Sim Kok Leong
Honored Contributor

Re: tar: excluding files from an archive

Hi,

Unless you install GNU tar, I think you have to workaround this by using a script eg.

#!/sbin/sh
list=""
for i in `find $1 -print`
do
if grep "^$i " /etc/tar.exclude >/dev/null 2>&1
then
:
else
list="$list $i"
fi
done
tar cvf /dev/rmt/0m $list
#end of script

/etc/tar.exclude includes all the files that are to be excluded.

Hope this helps. Regards.

Steven Sim Kok Leong
Deepak Extross
Honored Contributor

Re: tar: excluding files from an archive

My advice would be to 'inverse' your tar.exclude file into a tar.include file (which lists the files / directories to be included in the tar).
A one-time job, and it will make things easier in the long run. Your tar command will simply be:
tar cvf mytar `cat tar.include`
federico_3
Honored Contributor

Re: tar: excluding files from an archive

use this:

tar -cvf tarfile `find . -print | egrep -vx 'file1|file2|..|fileX'

or even better the GNU's tar from the site:


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

Ciao
Federico
John Carr_2
Honored Contributor

Re: tar: excluding files from an archive

cpio is a far better way to backup faster more reliable and supports option -f to exclude unwanted files or directories.

try something like this :

find . -depth -print | cpio -oB -f /unwantedfile > /dev/rmt/0m
Geoff Hartnell
Advisor

Re: tar: excluding files from an archive

Guys

Thanks for your help so far, but all of the suggestions fail in one way or another:

a) the 'do' loop fails because while it excludes the dir

/path/to/unwanted_file

it does not exclude

/path/to/unwanted_file/file


b) use of egrep fails because it excludes names like the unwanted file, so if the dir structure contains

/path/to/unwanted_file/file
/path/to/unwanted_file_needed/file

then both are are excluded, whereas the second of the above needs to be retained

c) the version of HP-UX that I have does not appear to support cpio -o -f


Any other ideas would be very welcome

Thanks,

Geoff
harry d brown jr
Honored Contributor

Re: tar: excluding files from an archive

Geoff,

As Federico stated (above), gnu's tar, which HP has ported, will do just what you want, plus it handles 2GB+ files, compression, and can do remote tapedrive writing!


live free or die
harry
Live Free or Die
Sanjay_6
Honored Contributor

Re: tar: excluding files from an archive

Hi Geoff,

The standard tar that comes with hp-ux has no option to exclude files from the archive which extrcting data. I think GNUtar has some support like that.

Hope this helps.

regds
Ian Dennison_1
Honored Contributor

Re: tar: excluding files from an archive

Scripting solutions,

change the 'grep "^$i " [file]' to be 'grep "^${i}$" [file] to set grep for complete line, (replace space with $)

then create a second 'if' and 'grep' statement checking 'grep "^$i/" [file] (force subdirectories).

Share and Enjoy! Ian
Building a dumber user
Patrick Wallek
Honored Contributor

Re: tar: excluding files from an archive

Have a look at the pax utility ('man pax' for more info.). It can write archives in either tar or cpio format and there is a '-c' option which does:

-c - Matches all file or archive members except those specified by the pattern or file arguments.
Robin Wakefield
Honored Contributor

Re: tar: excluding files from an archive

Hi Geoff,

Try this version:

=================================
#!/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
=================================

Rgds, Robin.
harry d brown jr
Honored Contributor

Re: tar: excluding files from an archive

Geoff,

try this:

find . -print | grep -v -E -f ./excludelist | grep -v "^\.$"| pax -w > /backuppath


pax , by default, writes archives in the ustar extended tar interchange format. (do a man pax)

live free or die
harry
Live Free or Die
Geoff Hartnell
Advisor

Re: tar: excluding files from an archive

Guys

A big thankyou to all who replied
- problem now sorted

Thanks,

Geoff