Issue:
How do I copy file and directories across to another server and preserve symlinks?
Resolution:
In order to preserve symlinks whilst copying files and directories across a network the use of the
rsync command is recommended. If
scp is used this will actually copy the symlinked file to the remote directory and lose the link relationship.
For example below we want to copy and preserve the symlink relationship between
test.log and
/home/test/test.log in the local
/rsync_test directory to machine serverOne's
/rsync_test directory.
Quote:
|
lrwxrwxrwx 1 root root 5 Jan 19 15:11 test.log -> /home/test/test.log
|
Two test cases will be used below to illustrate the point.
USING SCP
Quote:
|
scp /rsync_test/* serverOne:/rsync_test/
|
Listing the
rsync_test directory on machine serverOne shows the following:
Quote:
|
-rw-r--r-- 1 root root 5 Jan 19 15:11 test.log
|
In this example
scp copied the actual
test.log file to the destination directory, therefore losing the symlink relationship.
USING RSYNC
Quote:
|
rsync -a -e ssh /rsync_test/ serverOne:/rsync_test
|
Listing the
rsync_test directory on machine serverOne shows the following:
Quote:
|
lrwxrwxrwx 1 root root 5 Jan 19 15:11 test.log -> /home/test/test.log
|
In this example the symlink relationship has been preserved.
From the output above you can see
rsync can preserve symlink status and
scp can not. For further information see
man rsync and
man scp.
------------------------
Best Regards,
eUKShane 
http://www.eukhost.com