GNUTAR exclude directories


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users GNUTAR exclude directories
# 1  
Old 04-16-2003
Data 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
# 2  
Old 04-16-2003
The man page says:
Quote:
-X file
--exclude-from file Exclude files listed in file.
So what is the command you have been running that has failed?
# 3  
Old 04-17-2003
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.
# 4  
Old 04-17-2003
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
# 5  
Old 04-24-2003
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.
# 6  
Old 04-24-2003
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_a.../pf_index.html
http://www.eyetap.org/ece385/oreilly...pt/ch20_01.htm
# 7  
Old 04-25-2003
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. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Exclude directories in FIND command

Can you please help tweak the below command to exclude all directories with the name "logs" and "tmp" find . -type f \( ! -name "*.tar*" ! -name "*.bkp*" \) -exec /usr/xpg4/bin/grep -i "user_1" /dev/null {} + >result.out bash-3.2$ uname -a SunOS mymac 5.10 Generic_150400-26 sun4v sparc sun4v... (9 Replies)
Discussion started by: mohtashims
9 Replies

2. AIX

Exclude Directories in my tar command

Hi, im having some issues after i execute the next command: tar -cvf /varios/restore/test.tar -X /jfma/test1/excludefile /jfma | gzip -c > /varios/restore/test.tar.gz this creates the desired "test.tar.gz" file, but whe i try to open it it says "tar: 0511-164 There is a media read or write... (6 Replies)
Discussion started by: blacksteel1988
6 Replies

3. Shell Programming and Scripting

Global Pattern - exclude directories

All, I am trying delete folder by adding pattern not to delete certain folders. But i struck with error. When i use below command from command line, it works fine. shopt -s extglob rm -rf !(test1|test2|test3) But when i use the same in shell script, i get the below error. syntax... (6 Replies)
Discussion started by: vino_hymi
6 Replies

4. Shell Programming and Scripting

Perl exclude directories in command line

Hi, I use find command to list all the files in a directory and its sub-directories, but the problem is to exclude certain directories during search. Can i give the directory names in command line to skip them and search rest of the directories? For example i have directories: test ../test1... (1 Reply)
Discussion started by: nmattam
1 Replies

5. Shell Programming and Scripting

How to exclude the empty directories

Hi., I have a script, in which I am processing a files present in the directory types. ls -lrt | grep ^d | grep Dir_type | awk -f '{print $9}' |\ while read dir_name; do #operations done where Dir_type is the pattern in which directories get created. How to filter out empty... (2 Replies)
Discussion started by: IND123
2 Replies

6. Shell Programming and Scripting

Help - Find command to exclude sub-directories

Hi Forum. I'm trying to write a script that finds and deletes files that are older than 300 days. The script will read a table that contains the following 3 columns: 1st col: “Y” means sub-directory scan; "N" means no subdirectory scan 2nd col: sub-directory location 3rd col: File prefix... (7 Replies)
Discussion started by: pchang
7 Replies

7. UNIX for Dummies Questions & Answers

How to Exclude multiple directories from find command?

Hi, Can some one help me how to exclude multiple directories using find command.. I have the directory structure below. /a/a1/b1 /a/c1/c2 /a/d1/d2/d3 I want to exlcude a1,c2and d3 from the above using find,can some one suggest pls.. thanks in advance... Use code tags... (1 Reply)
Discussion started by: jagadish_gaddam
1 Replies

8. Shell Programming and Scripting

Find but exclude directories

Hello, I have a line in my script to find the files changed in the last 24 hours. It is as below: find /home/hary -type f -mtime -1 I now want to exclude a directory named "/home/hary/temp/cache" from the above find command. How do I add it to my script? Any help is appreciated. ... (9 Replies)
Discussion started by: tadi18
9 Replies

9. UNIX for Dummies Questions & Answers

find command to exclude directories

Howdy I have this directory structure ... eep eepaptest eepfatest eepgltest eep.old eeppoptest ehf ehfaptest ehfgltest ehp ehpgltest I want to find files in these directories, but I want to exclude eep, ehf & ehp. Cany anyone help with the correct command ?? (1 Reply)
Discussion started by: SmurfGGM
1 Replies
Login or Register to Ask a Question