LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-08-2010, 02:05 PM   #1
vbekker
Member
 
Registered: Aug 2010
Location: Brooklyn, NY
Distribution: CentOS
Posts: 38

Rep: Reputation: 0
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/*
 
Old 12-08-2010, 02:15 PM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

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

Hope this helps.
 
Old 12-08-2010, 02:23 PM   #3
stress_junkie
Senior Member
 
Registered: Dec 2005
Location: Massachusetts, USA
Distribution: Ubuntu 10.04 and CentOS 5.5
Posts: 3,873

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
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/*

Last edited by stress_junkie; 12-08-2010 at 02:26 PM.
 
Old 12-08-2010, 02:50 PM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
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.

Last edited by druuna; 12-09-2010 at 02:25 AM. Reason: spelling
 
Old 12-08-2010, 02:53 PM   #5
vbekker
Member
 
Registered: Aug 2010
Location: Brooklyn, NY
Distribution: CentOS
Posts: 38

Original Poster
Rep: Reputation: 0
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?
 
Old 12-08-2010, 03:11 PM   #6
stress_junkie
Senior Member
 
Registered: Dec 2005
Location: Massachusetts, USA
Distribution: Ubuntu 10.04 and CentOS 5.5
Posts: 3,873

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
Quote:
Originally Posted by vbekker View Post
stress_junkie,
that did it. any comments as to why it doesn't like the full path?
I wish I knew.

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.

Last edited by stress_junkie; 12-08-2010 at 03:21 PM.
 
Old 12-09-2010, 02:51 AM   #7
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
CVS Exclude : Exclude sub directories from check out On Linux from command line shajay12 Linux - Newbie 1 08-03-2009 12:36 AM
tar exclude HELP BassKozz Linux - Newbie 1 06-03-2009 03:41 AM
tar --exclude --exclude-from cefn Linux - Software 4 10-11-2005 07:31 PM
tar exclude-from drisay Slackware 1 12-23-2004 01:10 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:08 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration