tar exclude not working for directories

Still need help with Gentoo, and your question doesn't fit in the above forums? Here is your last bastion of hope.
Post Reply
User avatar
Jerri
Guru
Guru
Posts: 353
Joined: Thu Apr 03, 2003 9:47 pm

tar exclude not working for directories

Post by Jerri »

Well, as the subject suggests, i'm trying to backup some files (well, my whole system) but tar is not cooperating.

the following command *does* work:

Code: Select all

pwd
/usr/src/linux/kernel
tar  --exclude=irq -cvf new.tar ./
it succesfully removes the directory irq, and everything underneath it. However, if i'm trying to backup my entire system, i wont to specify the exact path to the directory to be excluded.

the following commands *do not* work:

Code: Select all

pwd
/usr/src/linux/kernel
tar  --exclude=/usr/src/linux/kernel/irq -cvf new.tar ./
tar  --exclude=/usr/src/linux/kernel/irq/ -cvf new.tar ./
tar  --exclude=/usr/src/linux/kernel/irq/* -cvf new.tar ./
tar  --exclude="/usr/src/linux/kernel/irq" -cvf new.tar ./
tar  --exclude="/usr/src/linux/kernel/irq/" -cvf new.tar ./
tar  --exclude='/usr/src/linux/kernel/irq' -cvf new.tar ./
tar  --exclude='/usr/src/linux/kernel/irq/' -cvf new.tar ./
snippet of whats tarred:

Code: Select all

intermodule.c
intermodule.o
irq/
irq/.autoprobe.o.cmd
irq/Makefile
irq/.manage.o.cmd
irq/internals.h
irq/spurious.c
irq/spurious.o
irq/.handle.o.cmd
irq/.built-in.o.cmd
irq/manage.c
irq/manage.o
irq/handle.c
irq remains! ahhh!!


I'm going crazy over this tiny little thing (i guess thats how it usually goes).

I'm all ears for suggestions.
User avatar
jdgill0
Veteran
Veteran
Posts: 1366
Joined: Tue Mar 25, 2003 10:12 pm
Location: Lexington, Ky -- USA

Post by jdgill0 »

Looking at the man page for tar:

Code: Select all

       --wildcards
              use wildcards with --exclude

       --wildcards-match-slash
              wildcards match slashes (/) with --exclude

       --exclude PATTERN
              exclude files based upon PATTERN

       -X, --exclude-from FILE
              exclude files listed in FILE

It looks like the slashes are the problem. You should try the --wildcards-match-slash option, or you can put /usr/src/linux/kernel/irq within a file and use the -X, --exclude-from FILE option, which I know will work.
User avatar
Jerri
Guru
Guru
Posts: 353
Joined: Thu Apr 03, 2003 9:47 pm

Post by Jerri »

no dice, i tried exclude-from FILE, same results. i'm really stumped here...

Code: Select all

[root][/usr/src/linux/kernel]: tar  --wildcards-match-slash --exclude=/usr/src/linux/kernel/irq/* -cvf new.tar * | grep irq
tar: new.tar: file is the archive; not dumped
irq/
irq/.autoprobe.o.cmd
irq/Makefile
irq/.manage.o.cmd
irq/internals.h
irq/spurious.c
irq/spurious.o
irq/.handle.o.cmd
irq/.built-in.o.cmd
irq/manage.c
irq/manage.o
irq/handle.c
User avatar
jdgill0
Veteran
Veteran
Posts: 1366
Joined: Tue Mar 25, 2003 10:12 pm
Location: Lexington, Ky -- USA

Post by jdgill0 »

OK. Tried this myself. The problem is because of the ./ is not an absolute path, hence the absolute path /usr/src/linux/kernel/irq does not match anything in ./.

For example, to backup /usr/src/linux without irq.

Code: Select all

tar  --exclude=/usr/src/linux/kernel/irq -cvf new.tar /usr/src/linux
User avatar
Jerri
Guru
Guru
Posts: 353
Joined: Thu Apr 03, 2003 9:47 pm

Post by Jerri »

thanks, that gives me some ideas :)
User avatar
Jerri
Guru
Guru
Posts: 353
Joined: Thu Apr 03, 2003 9:47 pm

Post by Jerri »

jdgill0 you are the man.

Thanks you so much :)
User avatar
jdgill0
Veteran
Veteran
Posts: 1366
Joined: Tue Mar 25, 2003 10:12 pm
Location: Lexington, Ky -- USA

Post by jdgill0 »

:) I actaully learned something myself. I never noticed this "quirk" about tar before. Guess I have been lucky and not run into it ever :!:

Anyways, glad I could help. Good luck.
Post Reply