It would be really useful if there was a way to tell tar to deference
symlinks for directories (and maybe files) specified on the command line.
Note that this is different from the "-h" option in that it would only
affect those paths on the command line and not symlinks found during the
archive process.
In my case, I want to backup a number of directories, but some of them
are actually symlinks (/var/cvs -> /mnt/raid/cvs). It would be esiest and
less prone to error to just "tar cvzf cvs.tgz /var/cvs/" and have it
work. As it is, the archive will have only the symlink to /mnt/raid/cvs
and none of the files.
I can think of a few ways of doing this...
1) If a directory is specified on the command-line, always dereference it
to the actual directory.
2) Dereference any directories that include the trailing slash. This is
consistent with the behavior of "tcsh" and "ls".
3) Add another option (in addition to "-h") that would force dereferencing
of command-line paths only.
I think #2 would be the best solution, the most likely to be of benefit, and
the least likely to cause any conflicts with existing usage.
Brian
( bcwhite@precidia.com )
-------------------------------------------------------------------------------
Sticks and stones may break bones, but words will shatter the soul.
I can't remember if I've passed this one on to you or not. Brian White asked if there were some way tar might in the future provide a mechanism to dereference symlinks specified on the command line, different from the -h option. The full text is at http://bugs.debian.org/48572 Thoughts? Bdale
Date: Thu, 28 Oct 1999 10:57:02 -0400
From: Brian White <bcwhite@precidia.com>
I can think of a few ways of doing this...
1) If a directory is specified on the command-line, always dereference it
to the actual directory.
That would be incompatible with existing practice, so I'd prefer not
to do without good reason.
2) Dereference any directories that include the trailing slash.
This is consistent with the behavior of "tcsh" and "ls".
POSIX says that trailing slashes should be ignored, so I think this
solution is unwise. I don't know about `tcsh', but `ls' doesn't care
about trailing slashes. E.g.:
$ mkdir d
$ touch d/f
$ ln -s d l
$ ls -l l
lrwxrwxrwx 1 eggert eggert 1 Dec 8 22:20 l -> d
$ ls -l l/
lrwxrwxrwx 1 eggert eggert 1 Dec 8 22:20 l -> d
$ ls -l l/.
total 0
-rw-rw-r-- 1 eggert eggert 0 Dec 8 22:20 f
3) Add another option (in addition to "-h") that would force dereferencing
of command-line paths only.
Why not just put trailing /. after the symlink to a directory? That
will cause it to be dereferenced. This works for all programs, not
just tar. E.g.:
$ tar -cf - l/. | tar -tvf -
drwxrwxr-x eggert/eggert 0 1999-12-08 22:20:34 l/./
-rw-rw-r-- eggert/eggert 0 1999-12-08 22:20:34 l/./f
It's true that it would be incompatible, but I think it's only incompatible
in a way that nobody would currently use. It seems unlikely that someone
would want to tar a single symlink specified on the command line.
Hmmm... I'm sure I checked that before I sent my report, but now I get
the same results as you. I wonder what I did differently then.
Mostly because I never thought of it! <grin> That works, though it
makes the stored paths look kinda ugly. Picky, picky, I know... :-)
There's only difficulty I see with that is some scripts get passed path
names (obviously without a trailing "/."), thus requiring a modification
to those scripts to first check if the passed path is a directory and append
a "/." if that directory happens to be a symlink.
A thought... Would requesting extraction of "dir/file" match a path of
"dir/./file" stored in a tarball? That could potentially cause some other
problems, too.
I wish I had some more ideas to offer, but I seem to be fresh out right
now.
Brian
( bcwhite@precidia.com )
-------------------------------------------------------------------------------
Understanding is a three-edged sword: your side, their side, and the truth.