I am trying to setup bi-direction or two way sync with rsync. In my case I only need to delete the files when syncing from B to A. So, I was thinking of running rsync twice as follow :
rsync -rtuv ./A/ ./B/ rsync -rtuv --delete ./B/ ./A/
This problem with this solution is that when I run rsync (B->A) which would be right after running the rsync (A-B), Any new file that get created in between the sync will also get removed.
Is there a way I can specify a time stamp as condition that it only delete the file if it created before this date/time.
Updated:
I understand there is a unison solution but the problem with unison is required to install on both ends. I am syncing with a remote server and I can not install unison on the remote end.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
rsync is the wrong tool for this task, for exactly the reasons that you have encountered. Instead, consider using unison:
unison A/ B/
The first time you run this it will identify files that are uniquely in A, and those that are uniquely in B. It will also flag those that are in both places and ask you to identify which is to be overwritten.
The next time you run this it will copy changes from A to B and also B to A, flagging any files that have been changed in both places for manual resolution.
mkdir A B date > A/date who > B/who unison A/ B/ # Lots of output from unison, showing synchronisation ls A date who ls B date who date > A/date unison A/ B/ # Lots of output from unison, showing synchronisation
There are a number of useful flags available for unison which help automate the process by defining assumptions and thereby reducing the number of questions you’re asked during the synchronisation.
Method 2
You could try osync which is designed for exactly this task. I once set up a complex sequence of rsync commands to do the job, but I now use osync.
https://github.com/deajan/osync
It uses rsync internally, so it should be suitable for any situation where you could use rsync.
Method 3
What you really need is Rclone. Rclone is rsync for cloud storage (box,dropbox,nextcloud,ftp etc) and local storage.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0