Operating System - HP-UX
1835681 Members
2700 Online
110082 Solutions
New Discussion

HELP?! :-/ Accidentally created symlink over existing dir

 
Trever Furnish
Regular Advisor

HELP?! :-/ Accidentally created symlink over existing dir

One of our DBAs was in the wrong directory by accident and and symlinked over top of an existing directory. Is there any way to recover the original directory entry, short of doing a tape restore?

Before you ask, no, I don't know the inode of the original directory entry.

Is there a recovery tool that can pull that inode info out of the raw filesystem? Is there some simple, magical, "no, I didn't really mean to ln -s a b, I meant ln -s a c" command that I simply haven't run into yet in my unix career? :-)
Hockey PUX?
6 REPLIES 6
James R. Ferguson
Acclaimed Contributor

Re: HELP?! :-/ Accidentally created symlink over existing dir

Hi Trever:

Removing a symbolic link (with 'rm') only removes the link, not the object pointed to by the link.

Regards!

...JRF...
Trever Furnish
Regular Advisor

Re: HELP?! :-/ Accidentally created symlink over existing dir

Hmmm. 1 point for helping me to realize I needed to clarify the question, James.

The name of the link was an existing file. The link took the place of that file in the directory. I need to get back the original file.

Perhaps this will explain better. The DBA did the equivalent of:

# cd /u01
# ls -CF
Oracle/ IAS/ foo/
# ln -s IAS Oracle
# ls -CF
Oracle@ IAS/ foo/

D'OH!

So in the steps above, "Oracle" was originally a directory, but now it's a symbolic link to the IAS directory.

And the problem is he didn't mean to get rid of the Oracle directory, so I need to get it back, if possible. As luck would have it,the machine was very recently rebuilt and the backups haven't started yet, so I can't even restore from tape for him.
Hockey PUX?
Bill Hassell
Honored Contributor

Re: HELP?! :-/ Accidentally created symlink over existing dir

Just rename the Oracle symlink. The symlink itself is unaffected but the underlying Oracle directory will be renamed. An ll -d Oracle will point to a now-nonexistent directory so you can remove the link. Then rename the original directory:

ll -d Oracle
... Oracle@ -> Oracle

mv Oracle Oracle1
ll -d Oracle*
... Oracle@ -> Oracle
... Oracle1/

rm Oracle
mv Oracle1 Oracle
ll -d Oracle
... Oracle/


Bill Hassell, sysadmin
Dennis Handly
Acclaimed Contributor

Re: HELP?! :-/ Accidentally created symlink over existing dir

Something wrong with your list of commands. You can't create a symlink over a file or directory without removing/renaming that file/directory.

Oops, if you try to do it over a directory, the symlink is added to the existing directory:
$ ls
DUMMY/ full_path.c
$ ln -s full_path.c DUMMY
$ ll
drwxrwxr-x 2 96 Nov 20 19:48 DUMMY/
$ ll DUMMY/
lrwxrwxr-x 1 11 Nov 20 19:48 full_path.c@ -> full_path.c

>Bill: Just rename the Oracle symlink. The symlink itself is unaffected but the underlying Oracle directory will be renamed.

Huh?? What type of filesystem, command and/or shell allows that?
Yogeeraj_1
Honored Contributor

Re: HELP?! :-/ Accidentally created symlink over existing dir

hi Trever,

I have tried to reproduce the same, but no luck!

# mkdir dir1
# mkdir dir2
# ln -s file1 dir1
# ll
total 0
drwxrwxrwx 2 root sys 96 Nov 21 08:41 dir1
drwxrwxrwx 2 root sys 96 Nov 21 08:41 dir2
-rw-rw-rw- 1 root sys 0 Nov 21 08:40 file1
-rw-rw-rw- 1 root sys 0 Nov 21 08:40 file2
# ln -s dir1 file1
ln: file1 exists
# ln -s file1 file2
ln: file2 exists
#

Please post a listing of the file system and more information about your OS so that we can have a better insight on the problem

kind regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Bill Hassell
Honored Contributor

Re: HELP?! :-/ Accidentally created symlink over existing dir

Dennis explained the situation. I wasn't paying attention to the ll command output. The scenario looks like this:

cd /tmp
mkdir Oracle
touch Oracle/someOLDfile

Now create the symlink as if it was replacing the directory:

ln -s Oracle Oracle

It works. But not like you would think:

ll Oracle
total 0
lrwx------ 1 root sys 6 Nov 21 07:23 Oracle@ -> Oracle
-rw------- 1 root sys 0 Nov 21 07:23 someOLDfile

As you can see, the symlink was actually created under the Oracle directory and is pointing to something called Oracle. However, if you cd to /tmp/Oracle and type two commands:

ll Oracle
lrwx------ 1 root sys 6 Nov 21 07:23 Oracle@ -> Oracle
ll Oracle/*
Oracle/* not found

Symlinks are tricky because they don't point to an object (directory, file, etc), they are actually an alias string. So the symlink was created UNDER the Oracle directory and now is meaningless because in the Oracle directory as there is no Oracle object for the symlink's alias. Be sure to use ll -Fd when looking at objects to make sure you aren't seeing the contents but the actual element.


Bill Hassell, sysadmin