Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rsync create symbolic links only

Tags:

shell

unix

rsync

I currently have rsync working well. It copies all my files from one directory to another directory. The only thing is it is physically copying the files.

I have a lot of large files that I don't want to have a duplicate of all the files. I just want to create a symbolic link in the new directory so that I can serve the data on a webpage. The source directory has some scripts and files I don't want the public to see. I'm moving the safe data to the web root (destination).

What I would like rsync to do is any new files in the source directory would create links into the destination. That way I am not using up my hard drive space like I currently am doing. What I have works perfect except for doing the symbolic link aspect to it. Is there a way to have rsync track and create symbolic links?

rsync -aP --exclude="file.sql" --exclude="*~" --exclude=".*" --exclude="*.sh" . ${destination}
like image 882
user983223 Avatar asked Aug 09 '12 16:08

user983223


2 Answers

You could use cp -aR -s (Linux or FreeBSD) or cp --archive --recursive --symbolic-link (Linux) to create symbolic links to the source files in the destination directory instead of copies. Note that -s is non-standard.

like image 40
Derek Mahar Avatar answered Oct 07 '22 03:10

Derek Mahar


It's not a symlink, but you might be able to work with --link-dest=DIR. It creates a hard link which will create a new name for the same file. This will behave similarly to a softlink as long as:

  • Both files are on the same filesystem
  • You don't plan to delete the original and not the copy (the symlink would break but a hard-link won't)
  • You don't have anything explicitly checking to see if it's a softlink
like image 170
Thomas Avatar answered Oct 07 '22 05:10

Thomas