Operating System - HP-UX
1830056 Members
1631 Online
109998 Solutions
New Discussion

tar or not to tar that is the question

 
SOLVED
Go to solution
Adam Noble
Super Advisor

tar or not to tar that is the question

OK people I have a quick tar query. I want to tar up the entire home directory apart from one subdirectory which has some rather large files within it. Is there a flag within tar to let me do this or am I better using some other utility such as cpio.
5 REPLIES 5
Jeff_Traigle
Honored Contributor

Re: tar or not to tar that is the question

There's no exclude option for tar (at least not HP's version) although you could probably play around with regular expressions for shell file name expansion to accomplish it. I don't know about cpio, but, if you use HP's fbackup(1M) utility, it allows for exclusions. The only downside to fbackup is that it's proprietary so the archive is not portable to other OSes.
--
Jeff Traigle
Peter Godron
Honored Contributor

Re: tar or not to tar that is the question

Adam,
temporarily change the permisssions on the subdirectory so tar can not back it up.
Then run your tar.
Then reset the permissions.

Ralph Grothe
Honored Contributor

Re: tar or not to tar that is the question

You could install GNU tar which I think knows the --exclude option.
Alternatively you could use HP's fbackup which has the -e option,
or you could do it the die-hard way with find and -prune (which involves some quoted bracketing) and pipe into cpio.
Madness, thy name is system administration
Coolmar
Esteemed Contributor

Re: tar or not to tar that is the question

This should work:

cd /home (whatever your home dir is)

tar cvf tarfile.tar `ls | grep -v exclude-dir-name`
Peter Nikitka
Honored Contributor
Solution

Re: tar or not to tar that is the question

Hi,

Coolmar's solution works only for toplevel dirs to exclude. A find/cpio solution can exclude directories at lower levels as well.
The following example excludes directories 'tmp' and 'debug':

cd
find . \( -name tmp -o -name debug \) -prune -o type f -print | cpio -pdv /backup/home.cpio

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"