SlackwareThis Forum is for the discussion of Slackware Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
As you can imagine, this is causing me plenty of headaches. Is there something I can do with tar to fix this? I can re-restore some of the important directories
Are you sure that using -C is not the problem? It puts you into root / but then you are trying to extract a symlink to the directory above it with the double dot short cut .. and that ought to have some consequences, since it won't exist.
if I am root, and restore the user's home directory relatively (i.e. /root/user/mfoley), the symlinks work:
Code:
$ tar -xvjpf /backup/2017-02-08-novatec-13.37.tar.bz2 user/mfoley
ls -l user/mfoley/mail/2016/turboTax2015
lrwxrwxrwx 1 mfoley develop 20 Apr 6 2016 turboTax2015 -> ../2015/turboTax2015
Thinking perhaps tar changed after applying 14.2 updates, I removed the original /user/mfoley and tried again:
Code:
$ tar -C / -xvjpf /backup/2017-02-08-novatec-13.37.tar.bz2 user/mfoley/mail/2015
$ ls -l /user/mfoley/mail/2015/turboTax2015
---------- 1 root root 0 Feb 9 08:40 turboTax2015
Nope, symlink still bad. Can anyone explain this behavior of tar? If not, it looks like my work-around is to restore all directories relatively under root, then move them to the right location.
Are you sure that using -C is not the problem? It puts you into root / but then you are trying to extract a symlink to the directory above it with the double dot short cut .. and that ought to have some consequences, since it won't exist.
OK, but the double-dotted file is several levels down in /user/mfoley/mail/2016. Why wouldn't it double-dot relative to the directory in which the link was created? I'm not saying you're wrong and my previous test may support your theory, but the behavior doesn't make sense. How would one ever restore a link with a relative reference to ../ ?
The tar -h option can do some very, very, odd things. And the guy who wrote that page doesn't know what he's talking about. My advice, don't go anywhere near that option. You certainly don't need it to restore an archive containing symlinks.
55020: to quote a few lines from the link you referenced:
Quote:
Symbolic links containing `..' or leading `/' can also cause problems when extracting, so tar normally extracts them last; it may create empty files as placeholders during extraction.
I'm trying to remember if I checked that file before the tar was actually completed. Possibly not. I was restoring that user only and, after it appeared to me that it had extracted all the files, I certainly CTRL-C'd the tar. Maybe if it had run to completion it would have fixed the reference.
Quote:
If you use the `--absolute-names' (`-P') option, tar will do none of these transformations.
To archive or extract files relative to the root directory, specify the `--absolute-names' (`-P') option.
Am I interpreting this correctly to mean that -P on an extract would not wait until last to extract a link properly and not create a placeholder? Would I have had to first save the archive with -P?
Quote:
Normally, tar acts on files relative to the working directory--ignoring superior directory names when archiving, and ignoring leading slashes when extracting.
When you specify `--absolute-names' (`-P'), tar stores file names including all superior directory names, and preserves leading slashes. If you only invoked tar from the root directory you would never need the `--absolute-names' option, but using this option may be more convenient than switching to root.
So, I don't really change to the root directory when creating (maybe I should?), but on extracts I use the -C / switch. Maybe I should also use that switch when creating the archive?
Well "after it appeared to me that it had extracted all the files, I certainly CTRL-C'd the tar" is (to put it kindly) material new information that was not previously disclosed.
About all those questions: I don't know. If it matters to you, think it through, try some experiments, and explore the solution space methodically.
Well "after it appeared to me that it had extracted all the files, I certainly CTRL-C'd the tar" is (to put it kindly) material new information that was not previously disclosed.
Indeed, there are several things that tar defers to the end of processing. Setting permissions on newly created directories is one (the final permissions might not allow creating of files there). It wouldn't surprise me at all that a placeholder might be left instead of a symlink if the extraction were permaturely interrupted.
I didn't know about tar setting permissions, or doing things with .., etc. after completion. In this case I was scratch-installing a new OS release. The whole tarball backup can take an hour to scan, so I restored specific directories only: /home, /root, /www/tomcat ... and yes, I certainly CTRL-C'd when it appeared the desired directory was done -- or so I thought it was done.
I'm going to assume this was my original permission/symlink problem. I'm too swamped with real work to experiment at the moment, but it makes sense and explains similar issues I ran into some time ago when also doing scratch installs. I've not run into this problem when restoring an entire partition in which case I would let it run to completion.
As I can now do a release upgrade w/o installing from scratch, or clone an OS from a complete partition tarfile, I may never run into this situation again, but good to keep in mind if I need to do a partial restore.
I didn't know about tar setting permissions, or doing things with .., etc. after completion.
Consider a non-root user extracting from a tar archive. If there were a directory in there with permissions that didn't allow writing, and tar set those permissions right away, then extraction of files into that directory would fail. So, tar always creates the directory initially with loose permissions, and defers the setting of the final permissions until the very end. I'm not sure what issues might arise with symlinks. Perhaps a symlink which, later in the archive, was replaced by a file or directory with the same name would be difficult to handle.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.