View previous topic :: View next topic |
Author |
Message |
Martux Veteran
Joined: 04 Feb 2005 Posts: 1917
|
Posted: Sun Jul 03, 2016 2:06 pm Post subject: Is a bidirectional sync with rsync possible? |
|
|
Hi folks!
I am wondering, is it possible with rsync to bidirectionally keep two folders in sync?
I would use unison for that, but it's not available on the client machine (KaOS). _________________ "Coincidence is God's way of remaining anonymous."
Albert Einstein
"The road to success is always under construction" |
|
Back to top |
|
|
augustin Guru
Joined: 23 Feb 2015 Posts: 318
|
Posted: Sun Jul 03, 2016 2:15 pm Post subject: |
|
|
How would this work?
If a file is present in system A but not in system B, does it mean that it's a new file that should be sync'ed to system B, or that it's an old file that got deleted in B and that should also be deleted from A?
How would a bi-directional sync figure out the answers to such questions?? |
|
Back to top |
|
|
Logicien Veteran
Joined: 16 Sep 2005 Posts: 1555 Location: Montréal
|
Posted: Sun Jul 03, 2016 2:39 pm Post subject: |
|
|
On a local machine you can keep to directories in sync by a symbolic or an hard link. On the network, Samba is there to share a directory between multiples machines. If you keep two directories in sync for a backup or any reason, a starting point can be to push the /A directory to the /B one, syncing existing directories and files but, without deleting anything, than pull /B to /A in the same way:
Code: | rsync -avz --max-delete=0 --progress --rsync-path='sudo rsync' --stats /A/ user@xxx.xxx.xxx.xxx:/B/
rsync -avz --max-delete=0 --progress --rsync-path='sudo rsync' --stats user@xxx.xxx.xxx.xxx:/B/ /A/ |
Note that the first rsync command will modify anything in the destination by it's source and than the second rsync will only add directories and files to the destination when occur. You may want to use a parameter who only modify the destination when a directory or a file is newer in time from the source. Rsync have several parameters who can be use to tune the sync. Just not use in the same command line a parameter who are incompatible with a precedent one. _________________ Paul |
|
Back to top |
|
|
cboldt Veteran
Joined: 24 Aug 2005 Posts: 1046
|
Posted: Sun Jul 03, 2016 5:49 pm Post subject: |
|
|
The issue of delete is up to the programmer to decide how to handle. Rsync can delete on receiving end, but the default is to NOT delete. Otherwise use "--delete" to delete extraneous files from destination directories.
Another switch that is essential, I think, is "-u" or "--update", which skips transferring of files that are newer on the receiving end. The rsync man page teaches by way of an example:
Code: | To synchronize my samba source trees I use the following Makefile targets:
get:
rsync -avuzb --exclude '*~' samba:samba/ .
put:
rsync -Cavuzb . samba:samba/
sync: get put |
The author has a remote machine named "samba". The "-b" switch preserves history relating to like-named files
Code: | With this option, preexisting destination files are renamed as each file is transferred or deleted. You can control where the backup file goes and what (if any) suffix gets appended using the --backup-dir and --suffix options. |
|
|
Back to top |
|
|
EmaRsk Apprentice
Joined: 07 Sep 2004 Posts: 158 Location: Italy
|
Posted: Sun Jul 03, 2016 10:37 pm Post subject: |
|
|
You could also consider using the DirDiff vim plugin.
It's probably not the right-tool-for-the-job™, but it has some similarities with Unison and maybe it's just enough for your needs. _________________ Please, avoid some common spelling errors:
http://theoatmeal.com/comics/misspelling |
|
Back to top |
|
|
|