Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Is a bidirectional sync with rsync possible?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
Martux
Veteran
Veteran


Joined: 04 Feb 2005
Posts: 1917

PostPosted: Sun Jul 03, 2016 2:06 pm    Post subject: Is a bidirectional sync with rsync possible? Reply with quote

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
View user's profile Send private message
augustin
Guru
Guru


Joined: 23 Feb 2015
Posts: 318

PostPosted: Sun Jul 03, 2016 2:15 pm    Post subject: Reply with quote

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
View user's profile Send private message
Logicien
Veteran
Veteran


Joined: 16 Sep 2005
Posts: 1555
Location: Montréal

PostPosted: Sun Jul 03, 2016 2:39 pm    Post subject: Reply with quote

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
View user's profile Send private message
cboldt
Veteran
Veteran


Joined: 24 Aug 2005
Posts: 1046

PostPosted: Sun Jul 03, 2016 5:49 pm    Post subject: Reply with quote

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
View user's profile Send private message
EmaRsk
Apprentice
Apprentice


Joined: 07 Sep 2004
Posts: 158
Location: Italy

PostPosted: Sun Jul 03, 2016 10:37 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum