[file] Two way sync with rsync

I have a folder a/ and a remote folder A/. I now run something like this on a Makefile:

get-music:
 rsync -avzru server:/media/10001/music/ /media/Incoming/music/

put-music:
 rsync -avzru /media/Incoming/music/ server:/media/10001/music/

sync-music: get-music put-music

when I make sync-music, it first gets all the diffs from server to local and then the opposite, sending all the diffs from local to server.

This works very well only if there are just updates or new files on the future. If there are deletions, it doesn't do anything.

In rsync there is --delete and --delete-after options to help accomplish what I want but thing is, it doesn't work on a 2-way-sync.

If I want to delete server files on a syn, when local files have been deleted, it works, but if, for some reason (explained after) I have some files that aren't in the server but exist locally and they were deleted, I want locally to remove them and not server copied (as it happens).

Thing is I have 3 machines in context:

  1. desktop
  2. notebook
  3. home-server

So, sometimes, server will have files that were deleted with a notebook sync, for example and then, when I run a sync with my desktop (where the deleted server files still exist on) I want these files to be deleted and not to be copied again to the server.

I guess this is only possible with a database and track of operations :P

Any simpler solutions? Thank you.

This question is related to file sync rsync two-way

The answer is


I'm not sure whether it works with two syncing but for the --delete to work you also need to add the --recursive parameter as well.


You could try csync, it is the sync engine under the hood of owncloud.


I'm now using SparkleShare https://www.sparkleshare.org/

works on mac, linux and windows.


Since the original question also involves a desktop and laptop and example involving music files (hence he's probably using a GUI), I'd also mention one of the best bi-directional, multi-platform, free and open source programs to date: FreeFileSync.

It's GUI based, very fast and intuitive, comes with filtering and many other options, including the ability to remote connect, to view and interactively manage "collisions" (in example, files with similar timestamps) and to switch between bidirectional transfer, mirroring and so on.


You can use cloudsync to keep a folder in-sync with a remote:

pip install cloudsync
pip install cloudsync-gdrive
cloudsync sync file:c:/users/me/documents gdrive:/mydocs

If the remote is NFS, you can use:

cloudsync sync file:c:/users/me/documents/ file:/mnt/nfs/whatevs

Rclone is what you are looking for. Rclone ("rsync for cloud storage") is a command line program to sync files and directories to and from different cloud storage providers including local filesystems. Rclone was previously known as Swiftsync and has been available since 2013.


Try this,

get-music:
 rsync -avzru --delete-excluded server:/media/10001/music/ /media/Incoming/music/

put-music:
 rsync -avzru --delete-excluded /media/Incoming/music/ server:/media/10001/music/

sync-music: get-music put-music

I just test this and it worked for me. I'm doing a 2-way sync between Windows7 (using cygwin with the rsync package installed) and FreeNAS fileserver (FreeNAS runs on FreeBSD with rsync package pre-installed).


You might use Osync: http://www.netpower.fr/osync , which is rsync based with intelligent deletion propagation. it has also multiple options like resuming a halted execution, soft deletion, and time control.


You could also try bitpocket: https://github.com/sickill/bitpocket


Examples related to file

Gradle - Move a folder from ABC to XYZ Difference between opening a file in binary vs text Angular: How to download a file from HttpClient? Python error message io.UnsupportedOperation: not readable java.io.FileNotFoundException: class path resource cannot be opened because it does not exist Writing JSON object to a JSON file with fs.writeFileSync How to read/write files in .Net Core? How to write to a CSV line by line? Writing a dictionary to a text file? What are the pros and cons of parquet format compared to other formats?

Examples related to sync

Android Studio how to run gradle sync manually? Laravel, sync() - how to sync an array and also pass additional pivot fields? node.js execute system command synchronously Two way sync with rsync

Examples related to rsync

Speed up rsync with Simultaneous/Concurrent File Transfers? How does `scp` differ from `rsync`? How to rsync only a specific list of files? rsync: difference between --size-only and --ignore-times rsync copy over only certain types of files using include option rsync - mkstemp failed: Permission denied (13) Using Rsync include and exclude options to include directory and file by pattern Copying files using rsync from remote server to local machine Why is this rsync connection unexpectedly closed on Windows? Copy or rsync command

Examples related to two-way

Two-way SSL clarification Two way sync with rsync