[Linux] Tar & symbolic links ?
Russ Brewer
russ@hq.mycity.com
Thu, 13 Jul 2000 11:44:02 -0400
Jack Sasportas wrote:
> When you backup a partition which has a symbolic link does the backup of
> that data reside in the symbolic directory path, or in the real
> directory path when you go to restore the data from a tar backup ?
>
> I have had some weird problems and restoring some data.
>
> Thanks...
>
> ___________________________________________________________
> Jack Sasportas
> Innovative Internet Solutions
> Phone 305.665.2500
> Fax 305.665.2551
> www.innovativeinternet.com
> www.web56.net
>
> _______________________________________________
> Linux mailing list
> Linux@flux.org
> http://www.flux.org/mailman/listinfo/linux
Heres how it seems to work:
Assume main file is /hold/myfile
Assume sym link to this file is /home/russ/myfile.sym
Therefore, /home/russ/myfile.sym is a symbolic link to /hold/myfile
>From the home directory issue this tar command:
tar cf archive.tar russ/myfile.sym
This works fine, in that you can now extract the symlink form the archive
if you need to restore the symbolic link.
However, you are out of luck with the above tar archive if the file you
need to restore is the main file,
/hold/myfile. It is not in the archive. A tar xf archive.tar command will
result in extracting the sym link. The deleted file (/hold/myfile in this
example) can not be recovered from this archive.
However, the "-h" option to tar provides some relief to this problem,but
it is an imperfect solution. Assuming the same example but you create the
archive as follows:
tar xhf archive.tar russ/myfile.sym
Now the only file in the archive becomes russ/myfile (NOT russ/myfile.sym)
and extracting the file will place in it the home/russ directory not the
/hold directory from which it originated! No sym link exists in the
archive. This is a problem because after the restore myfile in in the russ
directory not the hold directory and the sym link is not in the archive at
all.
So how do you archive both the symlink and the main file? AFAIK you have to
explicitly list them both in the original directive when creating the
archive. One way to do this is with the "-T filelist" option.
Continuing the above example, in the home directory create a file named
(arbitrarily) "filelist" and in this file place the following entries:
russ/myfile.sym
/hold/myfile
Then create a tar archive as follows:
tar -cPf archive.tgz -T filelist
This will capture both the sym link and the main file in the archive. Note
the -P option. This is needed to preserve the full path name to the "hold"
directory, without it /hold/myfile will become hold/myfile and any restore
will become relative instead of the desired (in this example) absolute
path.
To get a list of all the main files your symlinks point to you might do
somethink like:
ls -l | grep "^l" | awk '{print $NF}' > filelist
Russ Brewer
Systems Administrator
Mycity.com