Operating System - HP-UX
1833175 Members
2803 Online
110051 Solutions
New Discussion

Re: use tar but exclude certain files ?

 
SOLVED
Go to solution
Sammy_2
Super Advisor

use tar but exclude certain files ?

Hpux 11.0
=========
How do I tar up all files in /home/app except
the ones in the excludefile (see wildcard entry below)

# cat excludefile
/home/app/data/*/archive
/home/app/data/*/inbound/retrieve
good judgement comes from experience and experience comes from bad judgement.
10 REPLIES 10
Jeff_Traigle
Honored Contributor

Re: use tar but exclude certain files ?

With tar, you don't. There's no exclusion option in tar. You can use fbackup as long as you don't need the archive to be compatible with other flavors of Unix. Even with that, I'm not sure you can use wildcards as you've indicated... I think they have to be explicit paths. Of course, it wouldn't be terribly difficult to use "find" to generate a file of explicit paths that match your criteria to exclude.
--
Jeff Traigle
Ivan Ferreira
Honored Contributor

Re: use tar but exclude certain files ?

You could create a file with the names of all directories that you want to backup, then use

tar cvf /destination/file `cat filelist.txt`
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
Ivan Ferreira
Honored Contributor

Re: use tar but exclude certain files ?

Or I think that this may work:

tar cvf /destination/file `find /home/app/data -type f -exec ls {} \; | grep -E -v "archive|retrieve"`
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
Rodney Hills
Honored Contributor

Re: use tar but exclude certain files ?

You could use "pax" to create a tar file. It can read a list of files to copy. Using find and grep you can create a list that excludes those entries in excludefile.

find /home/app/data -print | grep -v -f excludefile | pax -w -f savehere.tar

HTH

-- Rod Hills
There be dragons...
baiju_3
Esteemed Contributor

Re: use tar but exclude certain files ?


Best option is to go for fbackup .


thx,
bl.
Good things Just Got better (Plz,not stolen from advertisement -:) )
Sammy_2
Super Advisor

Re: use tar but exclude certain files ?

Ivan,
I have too many directory to include files as I am tarring up the entire f/s.
I like your second method, but only drawback
is it will exclude archive directory in /home/app/archive as well. I think.

good judgement comes from experience and experience comes from bad judgement.
Sammy_2
Super Advisor

Re: use tar but exclude certain files ?

Rod,
The pax worked but it did not exclude files in my excludefile list. see below please.
Thanks

# pwd
/home/app
find . -print | grep -v -f excludefile | pax -w -f savehere.tar
# cat excludefile
./data/007916208/archive
./data/007941446/archive
./data/0079414460018/archive


fbackup may be only option although I am playing around with Ivan solution to see i can manually copy certain 2 or 3 archive directory that are not under /home/app/data but uder /home/app
good judgement comes from experience and experience comes from bad judgement.
Rodney Hills
Honored Contributor
Solution

Re: use tar but exclude certain files ?

Did the find | grep combination create the list properlly? Try sending the output to a file and verify that it excluded the paths you didn't want.

Also, I found I left off a key option to "pax". Add the "d" option to prevent it from walking directories.

So the correct line should be-

find /home/app/data -print | grep -v -f excludefile | pax -wd -f savehere.tar

HTH

-- Rod Hills
There be dragons...
Rodney Hills
Honored Contributor

Re: use tar but exclude certain files ?

One more thing...
To use "excludefile" as a grep pattern matcher, then each "*" must be preceded by a ".".
example-

/home/app/data/.*/archive

Because the "*" wildcard was looking for zero or more "/".

HTH

-- Rod Hills
There be dragons...
Sammy_2
Super Advisor

Re: use tar but exclude certain files ?

Rod,
I tried .* in the excludefile and just executed find .Apparently find does not
recognize wildcard in this case and thus include everything in my excludefile list. But, your suggestion
works great if I expand the directory names and not use *. It then gives me a tarball excluding archive and retrieve
(that is what i want). That's good enough for me

# cat excludefile
/home/app/data/.*/archive
/home/app/data/.*/inbound/retrieve

But, your suggestion
works great if I expand the directory names and not use *. It then gives me a tarball excluding archive and retrieve
(that is what i want). That's good enough for me. I guesss that is as good as it gets. Thansk a bunch for your help as
your solution got me what I wanted (using a workaround)

# cat excludefile
/home/app/data/costco/archive
/home/app/data/samclub/archive
/home/app/data/walmart/archive
/home/app/data/sears/inbound/retrieve
/home/app/data/bbuy/inbound/retrieve


Ivan,
Thanks to Ivan as well since his solution would work fine if I did not have any other archive directory.
good judgement comes from experience and experience comes from bad judgement.