linux - Symlinks are lost after running rsync to sync two directories
2013-09
I have two identically named directories with similar subdirectories and I would like to merge the contents of one into the other. I'm trying to use rsync to do this and I'm finding that symlinks appear to have been created in the destination directory, but then disappear the next time I access the directory (I would like to preserve symlinks).
An example (destination dir is currently empty):
Source directory:
/tmp/dir_3
Destination directory:
/dir_1/dir_3
The rsync command I'm using:
rsync -av /tmp/dir_3 /dir_1
The output of rsync seems to indicate that symlinks are being followed and if I cd into the destination directory and immediately execute the tree
command it shows the symlinks and the right number of directories and files (i.e. it matches what is in the destination directory). However, the second time I run the tree
command the symlinks are gone and I can confirm that with ls
.
The symlinks in question are a little tricky, but are linking entirely between subdirectories within in the Source directory. A simplified example:
/tmp/dir_3/data/33/22/bob
is a link to
../../../name/id
and
/tmp/dir_3/name/id/bob
is a link to
../../data/33/22
I've also tried adding the -l
option to the rsync command but that doesn't seem to make a difference (and I wouldn't really expect it to as -a
should copy links).
Any ideas what I'm doing incorrectly?
I have two linux box that i would like to keep in sync. I see option -avz syncs the remote with local but new local files are not pushed. How do i do this?
rsync is a one-way sync and it seems you want a two-way sync (files in both locations can change). There are other tools to do that -- unison is one.
- Unlike simple mirroring or backup utilities, Unison can deal with updates to both replicas of a distributed directory structure. Updates that do not conflict are propagated automatically. Conflicting updates are detected and displayed.
- Unison works between any pair of machines connected to the internet, communicating over either a direct socket link or tunneling over an encrypted ssh connection. It is careful with network bandwidth, and runs well over slow links such as PPP connections. Transfers of small updates to large files are optimized using a compression protocol similar to rsync.
- Unison is resilient to failure. It is careful to leave the replicas and its own private structures in a sensible state at all times, even in case of abnormal termination or communication failures.
- Unison is free; full source code is available under the GNU Public License.
rsync (despite having the name "sync") is only really one-way. You can have it delete files in the destination directory that don't exist in the source directory, but you can't simultaneously push and pull files both ways (you'll just need to run rsync again with the source and destination dirs swapped; I would recommend also the -u
option so that only newer files overwrite older ones).
See also: http://superuser.com/questions/34697/using-rsync-to-actually-sync