LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   tar and symbolic links (https://www.linuxquestions.org/questions/linux-software-2/tar-and-symbolic-links-827111/)

jimdeadlock 08-18-2010 08:45 PM

tar and symbolic links
 
I'm backing up my whole system to an external hard drive using tar and for the most part it works like a charm. However, I'm having trouble extracting symbolic links from the tarball, they are restored as empty files without any permissions or original ownership:

Code:

$ ls -l /home/jim/mysymlink
lrwxrwxrwx 1 jim  jim    22 2010-08-19 00:18 /home/jim/mysymlink -> /media/Maxtor/mysymlink

$ sudo tar cfpz /media/Maxtor/backup1.tgz --exclude=/media/Maxtor /

$ sudo tar xfpz /media/Maxtor/backup1.tgz home/jim/mysymlink

$ ls -l /home/jim/mysymlink
---------- 1 root root    0 2010-08-19 00:19 /home/jim/mysymlink

All other files can be extracted properly with correct ownership/permissions, it's only symbolic links I'm having the problem with. Any ideas?

smoker 08-19-2010 01:37 AM

Well if you exclude the symlink destination, what else is supposed to happen ?

jschiwal 08-19-2010 01:47 AM

If the target of the symbolic link is under the base directory being archived and is also archived, then the symbolic link will be restored correctly. Look at the tar info file and search for "symbolic".

colucix 08-19-2010 02:27 AM

Actually GNU tar preserves symbolic links, even if the target file does not exist anymore. Which version of tar are you running?
Code:

tar --version

jimdeadlock 08-19-2010 11:52 AM

@smoker - the exclusion was for my external hard disk when creating the archive, the symlinks are on my computer. They were included in the archive but it's when I try to extract them I'm having the problem.

@jschiwal - these requirements are all met and it's still not working properly :(

@colucix - I'm running Tar 1.22 on Ubuntu 10.10 (lucid)

smoker 08-19-2010 01:20 PM

If the symlinks were in the archive, then when you extracted the archive, presumably as root, it merely copied the archive contents over the existing symlinks. But the links in the archive were broken when you excluded /media/Maxtor - hence the current situation. Tar can follow symlinks if you tell it to, but you didn't and you excluded the destination anyway.

IMHO anyway ...

Have you tried testing with a symlink that points at a file that does get archived ?

jimdeadlock 08-19-2010 03:21 PM

Ahh yes that makes perfect sense now you've explained it and you're correct, other symlinks on the filesystem are extracting properly. Thanks so much!


All times are GMT -5. The time now is 12:50 AM.