Re: rsync and symbolic links



David Staschover wrote in <Tv3fg.31$y47.0@xxxxxxxx> on Tue, May 30 2006
18:17:

I am using rsync as a backup method to synchronize files between 2 linux
computers.

However, no matter what options I use, the absolute path goes away on the
remote system. It is very important for us to maintain the absolute path,
in case we need to switch to the backup server.

For example:

We are using rsync to copy symbolic link "/filename", to
"/backup/filename" on the backup server.

Here's what happens to the file:

lrwxrwxrwx 1 root root 40 Nov 2 2005 filename ->
/path/to/file becomes
lrwxrwxrwx 1 root root 40 Nov 2 2005 filename ->
path/to/file

Is there any way to retain the complete path on the backup server?


Is there any way to just make the symlink use a relative path, instead of an
absolute one? If you are putting the directory tree on the same place on
the backup server, that should work.

What I find rather interesting is that the file size of the symlink _should_
change if the path is changing:

fd0man@fd0man-laptop:~$ ln -s /path/to/file file
fd0man@fd0man-laptop:~$ ln -s path/to/file file2
fd0man@fd0man-laptop:~$ ls -l file*
lrwxrwxrwx 1 fd0man fd0man 13 2006-05-31 02:29 file -> /path/to/file
lrwxrwxrwx 1 fd0man fd0man 12 2006-05-31 02:29 file2 -> path/to/file
fd0man@fd0man-laptop:~$

As you can see, the file size is different in both situations -- the
file "size" of a symlink is actually just the count of characters to the
path in question.

That having been said, the path ".." in the root directory is always the
root directory, so if you run "cd .." in the root directory, you will stay
in the root directory. That means that while it may be ugly to do so, you
could actually have a symlink point to a seemingly non-existant location
and it will still work, for example, if your tree on the backup server is
in a different location in the filesystem then on the original.

Given that, the following should work:

fd0man@fd0man-laptop:~$ pwd
/home/fd0man
fd0man@fd0man-laptop:~$ ln -s ../../../../../../../usr usr-dir
fd0man@fd0man-laptop:~$ ls -l usr*
lrwxrwxrwx 1 fd0man fd0man 24 2006-05-31 02:33
usr-dir -> ../../../../../../../usr
fd0man@fd0man-laptop:~$ cd usr-dir
fd0man@fd0man-laptop:~/usr-dir$ pwd
/home/fd0man/usr-dir
fd0man@fd0man-laptop:~/usr-dir$ ls
bin games include java lib lib64 local sbin share src X11R6
fd0man@fd0man-laptop:~/usr-dir$ cd ..
fd0man@fd0man-laptop:~$ ls -l usr*
lrwxrwxrwx 1 fd0man fd0man 24 2006-05-31 02:33
usr-dir -> ../../../../../../../usr
fd0man@fd0man-laptop:~$

Of course, the actual relative path in this situation is only ../../usr, but
the symlink has extra, redundant '..' directories so that it can be moved
up to 7 directories away from the root directory and still be functional.

HTH,
Mike

--
Registered Linux User #417338, machine #325045.

A 2400 baud modem makes you want to get out and push!
.



Relevant Pages

  • Re: Bogus NullPointerExceptions
    ... A symlink is dropped under baseDir, externally, whose destination is ... This partition has zero files. ... * The attempt to delete the partition's empty root directory succeeds, ... If you think this is a "pleasant conversation" then you are hopelessly ...
    (comp.lang.java.programmer)
  • Re: Relative paths in require_once problem (possibly all include routines)
    ... settings in PHP.ini is by calling ini_setfunction which has to be ... The only solution i can think of right now is to use the absolute path ... require_once $relativePath. ... And the beauty of it is, if you have a different location for the root directory on your development site, the code still works in both places. ...
    (comp.lang.php)
  • Re: os.path.join
    ... absolute path, all previous components (on Windows, including the ... the root directory. ... The second path is overwriting the first because ...
    (comp.lang.python)
  • Re: Special characters in File objects on macintosh
    ... object displays this same changed string as seen in the absolute path. ... /Volumes with the name of the boot volume. ... that my PowerBook's "Macintosh HD" root directory can now be correctly ... Steve W. Jackson ...
    (comp.lang.java.programmer)
  • Re: Help: Absolute Path
    ... Acey wrote: ... Identify all paths that represent absolute path. ... which is a path relative to the current working directory. ... an absolute path is a path which starts at the root directory. ...
    (alt.os.linux)