Skip to content

bisync: investigate alternative approaches #5675

Closed

Description

@ivandeex

Synopsis

@Jwink3101 once noted in #5164 (comment)

There are two fundamental ways to do bi-sync:

  1. Compare each side independently to past state to develop a changelog. Propagate that change log
  2. Compare current state on each side using past state only for resolution (i.e. is this new on one or deleted on the other? Is it modified on one? Both?)
    • Additional use for tracking renames though this isn't needed if you don't mind rclone's current approach requiring shared hashes or ModTIme

You are doing the first. This has the advantage of being robust to time differences but also breaks with rclone's current behavior of --modify-window and the more general behavior of looking at current state. With approach 2, you can handle ModTime's not agreeing and/or size and/or hash like regular rclone.

Prior discussions

#5164 (comment) (JWink3101)

From bisync docs:

Note that on some cloud storage systems it is not possible to have file timestamps that match precisely between the local and other filesystems. Bisync's approach to this problem is by tracking the deltas against saved state on each side separately, and then applying the resulting changes on the other side.

There are two fundamental ways to do bi-sync:

  1. Compare each side independently to past state to develop a changelog. Propagate that change log
  2. Compare current state on each side using past state only for resolution (i.e. is this new on one or deleted on the other? Is it modified on one? Both?)
    • Additional use for tracking renames though this isn't needed if you don't mind rclone's current approach requiring shared hashes or ModTIme

Based on your comment, you are doing the first. This has the advantage of being robust to time differences but also breaks with rclone's current behavior of --modify-window and the more general behavior of looking at current state.

With approach 2, you can handle ModTime's not agreeing and/or size and/or hash like regular rclone.

The sub-bullet on the second is also interesting as it does allow you to track renames even if hashes aren't compatible. But you could also track with rclone's current behavior of looking at the extra files. Then use the past state to decide which side did the moving.

Approach 1 also requires the whole idea of --resync while it is implicit if you don't have past state in approach 2.

#5164 (comment) (ivandeex)

there are two fundamental ways to do bi-sync: ...
With approach 2, you can handle ModTime's not agreeing and/or size and/or hash like regular rclone.

Interesting. Sadly I'm not informed enough to discuss approaches now. It needs time to get literate :) Feels like switching to 2nd approach will mean a complete overhaul, but I'm not sure.

#5164 (comment) (ivandeex)

I really think it would have been better to [...] design the algorithm to be "rclonic"

The heart of rclone's omnivory change detection (runtime) lies around operations.equal, operations.checkHashes, et cetera. It's kept afloat by the astute test framework, in particular fstest.CheckListing, fstest.CheckHashes, fstest.CheckTime and [drums] retrying.

This code is not big in terms of LOC but its perceived complexity is high... while users continue to request for more change detection and filtering features.
My first approach to bisync about three months ago came across problems I can't clearly remember now so I tried it differently.

There is an ongoing proposal (#4810) that seeks to put this complexity under control. Ultimately we will need to inventory the state of affairs if we want to continue adding more features safely. I think we could continue this discussion in #4810. Maybe your experience in the synchronization field could help here?

when uncertain how to handle a situation, look at rsync. Is it worth the same idea with Unison?

Unfortunately rclone has already diverged (#1228, #3375, #5040, #5043, docs) from rsync :((
We can't easily fix that due to backwards compatibility concerns so there exists a waiting proposal (#4776) of rclone rsync besides rclone sync.

Mimicking Unison is a sound idea. However, if it would result in complete algorithm overhaul (not a critical problem) or if unison algorithms don't extend easily to the cloud world (that's worse), then I'd maybe think of developing an independent rclone unison.

#5164 (comment) (JWink3101)

One thing I toyed with when I first tried to make a two-way sync around rsync was to do two --dry-run calls A-->B and then B-->A. I then processed the actions and made my own decisions based on past state.

Could you do something like that but intrusive as opposed to a wrapper? The major downside of doing it from outside is two file listings but assuming the rclone structure allows, you can repeat it with the same listing. Then the initial compare implicitly follows the rclone logic as it stands today and in the future. And you end up with a lot fewer objects inside of your process since you've removed the ones that are the same.

This, BTW, also then aligns with what I called "method 2" for determining changes. (that is, being based first on current state rather than propagating changes. Both work but I still believe to be way more robust in the real world).

#5164 (comment) (cjnaz)

(Perhaps the rsync mode is a different algorithm, but assuming it applies to bisync...)
Regarding do two --dry-run calls A-->B and then B-->A, I think the change detection must be based on a prior state/history file/db/etc. This is needed in order to detect deletes. For rclonesync I considered making a single LSL file that represents both paths. This would have required generisizing this listing file format a bit and supporting mod-time tolerance. The value is limited - cuts memory usage, and designs out the possibility of divergence since both paths are compared to the same master history list. In rclonesync V3.2 I added a final compare of the final LSL files since the divergence bug did come up - actually triggered by an rclone bug in V1.52. Memory footprint can be a big deal. One rclonesync user had abut 2M files and ran out of memory. I optimized rclonesync to get it down to two in-memory file listings at any time. I understand that rclone deals with the file system recursively by directory rather than the whole tree?

#5164 (comment) (JWink3101)

I think the change detection must be based on a prior state/history file/db/etc.

Yes and no. I am not saying you don't need it for deletes. You do (as you note). But you do not need to detect changes and then propagate. That is what I referred to as method 1. The alternative (and I think much better and more robust) is to FIRST compare the current state and then use the previous state to detect whether it was a delete or a new file

How to use GitHub

  • Please use the 👍 reaction to show that you are affected by the same issue.
  • Please don't comment if you have no relevant information to add. It's just extra noise for everyone subscribed to this issue.
  • Subscribe to receive notifications on status change and new comments.

Activity

  1. added this to the Help Wanted milestone on Oct 8, 2021
  2. self-assigned this
    on Oct 8, 2021
  3. Jwink3101 commented on Oct 8, 2021

    @Jwink3101
    Contributor

    Wow. Lots of work putting this together and citing it.

    I do not know golang but I am happy to contribute to any discussion.

    If it helps, I started to put together my thoughts on my tool, syncrclone vs rclonesync-V2 and/or rclone bisync.

    Also, this may be outdated and/or wrong. I will happily modify it.


    Let's be 100% clear and upfront. I AM BIASED. I wrote syncrclone to fill a need not met by bisync.

    This is just my comparison thoughts. I really do appreciate both and I think you should pick the one that works best for you and your use case.

    The thing to remember is that bi-directional synchronization is fundamentally harder than mirroring because you need to keep the state. And therefore, it is also more opinionated.

    • Mode of configuration
      • syncrclone: Config file (path specified implicitly or explicitly)
      • bisync: Command line flags
      • Command line is cleaner and more consistent with rclone but there is a lot of configuration that needs to be kept (e.g. filters, etc) so I like the config file.
    • Change Propagation
      • syncrclone: Compare current state and use previous to resolve conflicts
      • bisync: Propagate differences between current and previous to both sides, then compare
      • Theoretically both should be identical but syncrclone is more robust to issues with knowing the previous state. It also removed the need for --fist-sync type flags and bisync safety mechanisms. If they have never been synced before, you get the union of the two sides which is safer. No deletes. It also better matches how rclone currently does the comparison
    • Comparisons:
      • syncrclone: mtime, size, hash
      • bisync: mtime
      • Reliance on mtime restricts which remotes can be used. mtimes can also be fragile when restoring from backups
    • Previous state:
      • syncrclone: Stored inside each remote and named based on a (set) unique name for the pair
      • bisync: Global storage on the machine itself. (note: I am less sure about this. It applied to rclonesync-V2)
      • Saved state on the machine means that if you sync two remotes (e.g. OneDrive to Google Drive), you need to use the same machine. Also can lead to issues with paths and duplicates
    • Rename Tracking:
      • syncrclone: Optional. Settable with mtime+size, hash, or size alone (though latter not advisable)
      • bisync: None
    • Reduce re-hashing:
      • syncrclone: Optional. Can keep previous hashes
      • bisync: None (but also no need)
      • syncrclone can use hashes to track renames even if the respective remotes do not share a common hash
    • Backups:
      • syncrclone: Optional
      • bisync: None
    • Delete Fail Safe
      • syncrclone: None
      • bisync: Yes. Can set a max-deletes
      • syncrclone has bisync protections including the default design which will not delete from mis-specified remotes
    • Complexity
      • syncrclone: Much more complex
      • bisync: Simpler approach
      • Options and power adds complexity. Part of the comprimise
    • Speed (untested but a good guess)
      • syncrclone: while somewhat optimized, much slower than bisync because it wraps it
      • bisync: Way faster and more efficient!
  4. Xelbayria commented on Jul 14, 2023

    @Xelbayria

    I was doing some research to see if there are any software that have a better bisync, unfortunately, none of them have what I am looking because most of them use hash, mtime, or size. What I am looking for is content. Here is the detail below:


    Example

    file#1 via Path1

    Hello World!
    How are you?
    

    file#1 via Path2

    Hello World!
    Your name is
    

    if both files' mtime is to be on the same day, but at different time OR The size of these 2 different File#1 are same. To have the same updated file on both path1 and path2. it would create conflict files "file#1..path1" and "file#1..path2".

    The key to merge the content of the 2 file is to create an algorithm that could compare the content of 2 files like so

    file#1 via Path1

    <strike>Hello World!</strike>
    How are you?
    

    file#1 via Path2

    <strike>Hello World!</strike>
    Your name is
    

    the algorithm would see the similar content that don't need to be copied. it only need to copy the difference from Path2 to Path1 and delete the file via Path2, and copy the updated file to Path2

    it would look like this:
    File#1

    Hello World!
    How are you?
    Your name is
    

    The system above can be done the other way from Path1 to Path2, and then delete the File#1 via Path1 and copy the updated file.

    My idea may not work for some cases but it could work for other cases. It depends. The Algorithm could take a lot of work to make it possible. There could be a different way (better than the idea above). Anyway, I gotta make a few changes to the way I use rclone bisync blc I just thought of a different way that could work for me.

  5. nielash commented on Aug 20, 2023

    @nielash
    Contributor

    most of them use hash, mtime, or size. What I am looking for is content.

    It's an interesting idea, but it's hard to imagine this being workable for Bisync, since Bisync needs to also work for files that aren't text-based. For example, what would happen if you tried to merge the content of an image / audio / video / zip file? Very possibly some serious data corruption.

    You might consider checking out google/diff-match-patch, which might be closer to what you're looking for. It's the library that powers Google Docs and makes it possible for multiple users to edit a text document at the same time.

  6. Xelbayria commented on Aug 20, 2023

    @Xelbayria

    It's an interesting idea, but it's hard to imagine this being workable for Bisync, since Bisync needs to also work for files that aren't text-based. For example, what would happen if you tried to merge the content of an image / audio / video / zip file? Very possibly some serious data corruption.

    ah yes, I forgot about these types of files. I was only focused on text-based. Thanks for the info. I'll look into google/diff-match-patch

  7. added a commit that references this issue on Dec 15, 2023
    7613c3f
  8. added a commit that references this issue on Jan 20, 2024
    4bde7f2
  9. added a commit that references this issue on Jan 20, 2024
    b421664
  10. added a commit that references this issue on Jan 23, 2024
    f70a4c6
  11. moved this to Done in bisyncon Aug 20, 2024
  12. added a commit that references this issue on Jul 20, 2026
    d280cea
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

  • Status
    Done

Relationships

None yet

Development

No branches or pull requests

Issue actions