LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   tar with --exclude and/or --exclude-from (https://www.linuxquestions.org/questions/linux-newbie-8/tar-with-exclude-and-or-exclude-from-849116/)

vbekker 12-08-2010 02:05 PM

tar with --exclude and/or --exclude-from
 
Hi,
Please shed some light on the --exclude and/or --exclude option within tar. I've searched the forums and followed all the advices. using full path of directories and also tried using a file to include all the exclusions, yet it still includes the unwanteds. Thank You

Code:

tar cvzf ${backupdir}/jira-home.${today}.tgz $origdirname --exclude-from /opt/jira/files_to_exclude_from_backup
file
Code:

/opt/jira_home/caches/indexes/comments/*
/opt/jira_home/caches/indexes/entities/portalpage/*
/opt/jira_home/caches/indexes/entities/searchrequest/*
/opt/jira_home/caches/indexes/issues/*


druuna 12-08-2010 02:15 PM

Hi,

Shouldn't that be: --exclude-from=/opt/jira/files_to_exclude_from_backup?

Hope this helps.

stress_junkie 12-08-2010 02:23 PM

You're not alone. I've always had trouble getting that feature to work reliably.

You might try just putting the name of the directory to exclude, not the full path, as in
Code:

comments/*
portalpage/*
searchrequest/*
issues/*


druuna 12-08-2010 02:50 PM

Hi,

These work (just tried, using GNU tar):

--exclude
tar czf name_tar_file.tar --exclude='insert_pattern' target/

--exclude-from
tar czf name_tar_file.tar --exclude-from='insert_file_name' target/
The patterns in the exclude file and the target should both be full path or relative.

The tar command posted in post #1 would look like this when using --exclude-from:
Code:

tar cvzf ${backupdir}/jira-home.${today}.tgz --exclude-from='/opt/jira/files_to_exclude_from_backup' $origdirname
If that doesn't work you might want to look at $origdirname, it should expand to a full path (which you also used in your exclude file).

Hope this helps.

vbekker 12-08-2010 02:53 PM

druuna,
seems to work both ways, i didn't put the equal sign since the "man tar" doesnt call for it...but it does work both ways.

stress_junkie,
that did it. any comments as to why it doesn't like the full path?

stress_junkie 12-08-2010 03:11 PM

Quote:

Originally Posted by vbekker (Post 4185110)
stress_junkie,
that did it. any comments as to why it doesn't like the full path?

I wish I knew. :scratch:

It may have something to do with the way tar strips off the leading path elements to the source directory. I always change my working directory to / before I run tar. The tar utility strips off the / part of the path when it creates the file names in the archive file. We all knew that, but maybe this exclude thing is related to that.

druuna 12-09-2010 02:51 AM

Hi,

What does $origdirname expand to? Is it the full path to your target directory (already mentioned this in reply #4)?

This works, with or without a full path in the exclude file: tar -cf test.tar --exclude-from='exclude.me' /full/path/to/target/

Content of exclude.me: /full/path/to/target/pattern

This I cannot get to work if the files in the exclude file have a full path: tar -cf test.tar --exclude-from='exclude.me' target/

If I remove the full path from the files in the exclude file it does work (i.e. content is: pattern)

BTW: Using an equal sign is indeed not needed although it is mentioned in the official gnu tar docs.


All times are GMT -5. The time now is 06:23 PM.