LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-06-2007, 05:50 PM   #1
Johng
Member
 
Registered: Feb 2002
Location: NZ
Distribution: Mint Suse
Posts: 345

Rep: Reputation: 30
Tar and symlinks


I want to save a directory that has one or more symlinks without all the files that the symlink(s) point to (ie I don't want to follow the symlinks).

The -h option is to follow symlinks, but if I don't include the -h, tar does follow the symlinks by default.

How do I stop tar (version 1.15.91) from following symlinks??
 
Old 01-06-2007, 07:30 PM   #2
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,141

Rep: Reputation: 168Reputation: 168
I'm using tar (GNU tar) 1.16 and if I don't use the -h option, I do get symlinks in the archive.
 
Old 01-06-2007, 07:47 PM   #3
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668
Just to make sure we have the right reference:

"follow" means go get the file it points to rather than getting the link itself.

You can do exclude of any file. Just because you get the symlink in your backup doesn't mean you get the file it points to unless it is also in your selection criteria.

Many backups include both the symlink and the file it points to but that isn't because it was "followed" but rther because they were both in the selection.

If you have two directories:

dir1
dir2

dir1 contains
file1
file2
sym1
sym2

dir2 contains
file3
file4

If sym1 points at file1 and you backup dir1 you're going to get both the symlink and the file it points at. If sym2 points to file3 and you backup dir1 you'll get a symlink that says it points to file3 but you won't get file3 itself. So on the restore (assuming you didn't do it to the machine that had dir2 on it) you would have a broken symlink.

The "-h" backup of dir1 would actually remove the symlinks and pull in file1 with the name of sym1 and file1 and file3 with the name of sym2. (Note you'd have file1 come back in both as file1 and as sym1 on the restore).

As noted though tar allows for excluding files either with the --exclude PATTERN (to specify on command line) or --exclude_from FILE (to exclude by reading a FILE into which you had listed the files to exclude)

Of course you can always use find to modify things:

find /dir1 -type f |tar ....

Would tell it to only pipe regular files into the tar command.
 
Old 01-07-2007, 03:31 AM   #4
Johng
Member
 
Registered: Feb 2002
Location: NZ
Distribution: Mint Suse
Posts: 345

Original Poster
Rep: Reputation: 30
Thank you jlightner. I understand your description, and it is as I expected.

However, whereas tar version 1.15.1 does just as you describe, version 1.15.91 included with Mandriva 2007 follows the link, ie it includes the files in the tar that the link points to.
 
Old 01-07-2007, 09:05 AM   #5
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668
Interesting. Latest I'm using is 1.15.90-1FC5 (On Fedora Core 5) and it still operates the way I describe.

Did some Google searches but found no mention of this but some other bugs in 1.15.91 that continued into 1.16. You may wish to have a look at the man page on your system that has 1.15.91 and and see if it has any references to following links by default.

I did see some discussion of a change regarding hard links for symbolic links but that was introduced in 1.13 so isn't likely the issue.

It may be you've found a bug. If so you may wish to go to the GNU site for tar and report it. The site is:
http://www.gnu.org/software/tar/
 
Old 01-07-2007, 10:02 AM   #6
Harmaa Kettu
Member
 
Registered: Apr 2005
Location: Finland
Posts: 196

Rep: Reputation: 30
Quote:
Interesting. Latest I'm using is 1.15.90-1FC5 (On Fedora Core 5) and it still operates the way I describe.
The newest stable release of tar (1.16.1) works that way too.

I think there are three possibilities:
  1. It is caused by some Mandriva-specific patch. Check the source rpm.
  2. The behaviour was changed in tar 1.15.91 but was later changed back.
  3. Johng has alias tar="tar -h" somewhere and does not know/remember it.

Quote:
It may be you've found a bug. If so you may wish to go to the GNU site for tar and report it. The site is:
http://www.gnu.org/software/tar/
No, it should be reported to Mandriva developers, of course assuming that (1) or (2) above is the cause and there isn't an updated package available already.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
how can i decompress this tar.tar file? hmmm sounds new.. tar.tar.. help ;) kublador Linux - Software 14 10-25-2016 02:48 AM
BackUp & Restore with TAR (.tar / .tar.gz / .tar.bz2 / tar.Z) asgarcymed Linux - General 5 12-31-2006 02:53 AM
tar | ssh (tar > .tar) syntax issues EarlMosier Linux - Software 6 12-21-2006 12:28 AM
tar and symlinks? neocookie Linux - General 2 08-07-2006 05:08 AM
tar not keeping permissions of symlinks exodist Linux - Software 1 06-14-2006 08:33 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:56 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