LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   tar: "preserve the symbolic links" (https://www.linuxquestions.org/questions/linux-newbie-8/tar-preserve-the-symbolic-links-927221/)

julian16 02-02-2012 01:40 PM

tar: "preserve the symbolic links"
 
I have a need to migrate a web site tree and I wish to "preserve the symbolic links" with tar -- that is, to keep the symbolic link "as is" without copying the targeted files. The regular 'tar cf' copied target files for each symbolic link thus duplicated the files many times that I lost track which one should be the "original" file on the new site.

I used tar option 'h' as in 'tar chf' but that does the same as the default behavior. I failed to find which option does the opposite. Any advice please?

joe

fukawi1 02-03-2012 12:50 AM

Well for me this works..

Code:

~/tmp $ tar -cpvzf /tmp/tarball.tar.gz *
file1
file10
file2
file3
file4
file5
file6
file7
file8
file9
linkname
~/tmp $ tar -ztvf /tmp/tarball.tar.gz
-rw-r----- fukawi1/fukawi1  0 2012-02-03 17:33 file1
-rw-r----- fukawi1/fukawi1  0 2012-02-03 17:33 file10
-rw-r----- fukawi1/fukawi1  0 2012-02-03 17:33 file2
-rw-r----- fukawi1/fukawi1  0 2012-02-03 17:33 file3
-rw-r----- fukawi1/fukawi1  0 2012-02-03 17:33 file4
-rw-r----- fukawi1/fukawi1  0 2012-02-03 17:33 file5
-rw-r----- fukawi1/fukawi1  0 2012-02-03 17:33 file6
-rw-r----- fukawi1/fukawi1  0 2012-02-03 17:33 file7
-rw-r----- fukawi1/fukawi1  0 2012-02-03 17:33 file8
-rw-r----- fukawi1/fukawi1  0 2012-02-03 17:33 file9
lrwxrwxrwx fukawi1/fukawi1  0 2012-02-03 17:32 linkname -> /tmp/link_dest/

That is the normal way i create a tar. I would imagine the -p option is preserving the permissions (the 'lrwrwxrwx') when it adds the link.

Dark_Helmet 02-03-2012 01:11 AM

The tar command should preserve symbolic links by default. I just tried a couple different attempts on my system using "tar cvjf tarball.tar.bz2 testdirectory/". I had links inside testdirectory that pointed to files within the directory and links that pointed outside the directory. All links were created--no dereferences.

Like I said, tar should preserve the symbolic links by default. So, you might want to check two things:

1. See if you have an alias for tar that includes the '-h' option automatically
2. Check your version of tar against any possible bug reports

For reference, my tar:
Code:

user@localhost$ tar --version
tar (GNU tar) 1.23
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by John Gilmore and Jay Fenlason.


julian16 02-04-2012 11:24 PM

Thank you both for your input. Our older RH Linux server was upgraded hence I could not verify. What you describe is repeatable on our new linux box though. Many thanks for taking time. Appreciated!


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