GNUTAR exclude directories

Hi,

Can anyone help me with the following:
I want to make a backup from my (AIX) system.
But I don't want to backup a couple of temp-directories.
I tried it with the X-option, but that didn't work.

I hope that someone can help me.
Thanks in advance.

Corine

The man page says:

So what is the command you have been running that has failed?

Well the situation is as follows.
I've got a couple of directories containing files.
/appl/data
/appl/data/temp1
/appl/data/temp2

Now I would like to backup the directory /appl/data, but NOT the 2 temp directories.

So my command was as follows:

find /appl/data -name 'temp*' -prune -o -print | xargs tar -cvf /tmp/datadir.tar

This works but not completely because in the tar-file it is:
first everything (so also the temp-dir) and appended to the file is exactly what I want (so /appl/data and not the temp-dir). I am wondering what am I doing wrong ?
I hope someone can help me.

We seem to have several problems here....

xargs collects as many arguments as will fit on a line and then invokes the given program. A find command might find 1000's of files. So rather than, say, doing an "rm" 1000's of times, it better to use xargs. Then you may only use a few dozen rm commands, each one having a full argument list.

But this doesn't extend to "tar cvf /some/file". If you have too many arguments for one command line, you will get two command lines. The second "tar cvf /some/file" will overwrite the contents of the first. If you are not encountering this problem, you must not have very many files.

Next, when you ask tar to backup a directory, it will backup the contents of the directory as well.
So:
tar cvf /tmp/data.tar /appl/data /appl/data/somefile
is not going to backup one directory and one file. That "/appl/data" will cause tar to pick up the whole thing. The /appl/data/somefile will put a second copy of somefile in the archive. Your find command will output /appl/data as its first line. That already gets you everything.

And none of this has anything at all to do with exclude files which is where the thread started.

What you're supposed to do is to create a file and put the stuff in it that you want to exclude. So, for example, edit the file /tmp/ExcludeFile and put in the following two lines:
/appl/data/temp1
/appl/data/temp2
Then use the command:
tar cvfX /tmp/datadir.tar /tmp/ExcludeFile /appl/data

I tried it, but it didn't work for me.

Now I've got a way that seemed to work.
It is:

tar -cvf /tmp/datadir.tar --exclude=temp* /appl/data

This seems to work, but it now also excludes the files temp.txt that are in /appl and that is not right.
So if anyone can help me a bit further would be nice.

TheBlueLady,

What Perderabo wrote at the end of his post really should work for you.. I'd double-check and make sure you tried it exactly like he said..

I think you could also do it more the way you're saying by trying this:
cd /appl/data
tar -cvf /tmp/datadir.tar --exclude=/temp1/* --exclude=/temp2/* .

I'm not sure why you're concerned with files excluded in /appl though, since you said you only wanted to archive the subdirectory /appl/data

References:
http://www.cs.vassar.edu/SysNews/backups.html\#doit
http://www.itworld.com/nl/unix\_sys\_adm/08152001/pf_index.html
http://www.eyetap.org/ece385/oreilly/unix/upt/ch20_01.htm

Hi oombera,

What Perderabo wrote sounds good, but really doesn't work for me, I just tried it again, the temp-directories still are in the archive. Also the way you described didn't work for me. Then the temp-directories are again in my archive.

But I've got a way that does work for me, it is not ideal, but it is working. It is the following:
tar -cvf /tmp/datadir.tar --exclude=temp1 --exclude=temp2 --exclude=temp3 /appl/data

You were also wondering why I am concerned with this. Well that is because of my daily backup of the whole system. Every day I want to make a backup on tape of the whole system, but not of the temp-directories. While the backup is being made other proces can be running changing files in the tempdirectories. Files in these directories change while in the meantime backup is trying to write them to tape, because of this the backup can crash. So that is the reason. Hope you understand me.
Anyway I am very thankful for all your help. :slight_smile: