I need to "install" a bunch of files to another directory keeping the directory structure of the source files intact. For example, if I have ./foo/bar/baz.txt
going to /var/www/localhost/webroot/
I want the result to be /var/www/localhost/webroot/foo/bar/baz.txt
. rsync
has this capability in --relative
, but when I did this I discovered it wasn't friendly to symlinks:
$ ls -ald /var/www/localhost/webroot/ | grep ^l
lrwxrwxrwx 1 www-data www-data 15 2014-01-03 13:45 media -> ../static/media
lrwxrwxrwx 1 root root 13 2014-02-24 13:47 var -> ../static/var
$ rsync -qrR . /var/www/localhost/webroot/
$ ls -ald /var/www/localhost/webroot/ | grep var
drwxr-xr-x 3 root root 4096 2014-02-24 13:52 /var/www/localhost/webroot/var
So you see the symlink is no longer a symlink – the files were copied to the wrong place!
rsync
also has the --no-implied-dirs
option, that superficially seems to do what I want, but it only works as I intend when not doing a recursive rsync, so I have to:
find . -type f -print0 | xargs -0I{} rsync -R --no-implied-dirs {} /var/www/localhost/webroot/
Is there any more direct way to accomplish this mirroring of files without wiping out intermediate symlink directories (with or without rsync)?