cjnaz / rclonesync-V2

A Bidirectional Cloud Sync Utility using rclone
MIT License
355 stars 39 forks source link

First-sync optimization #66

Open eric-void opened 3 years ago

eric-void commented 3 years ago

Command line help for flag "--first-sync" says: "First run setup. WARNING: Path2 files may overwrite path1 versions. Consider using with --dry-run first. Also asserts --verbose."

Looking at full documentation (and by checking the code) this is wrong. Path1 file may overwrite path2 versions!

Another thing: looking at the code there is a lot of work to copy Path2 files not in Path1, and then do an "rclone sync" from Path1 to Path2. Why don't you just do and "rclone copy" from Path1 to Path2, and then an "rclone copy" from Path2 to Path1? Something like this:

        logging.info(">>>>> --first-sync copying Path1 to Path2")
        # NOTE:  --min-size 0 added to block attempting to overwrite Google Doc files which have size -1 on Google Drive.  180729
        if rclone_cmd('copy', path1_base, path2_base, filter_file=user_filter_file, options=switches + ['--min-size', '0']):
            return RTN_CRITICAL
        logging.info(">>>>> --first-sync copying Path2 to Path1")
        # NOTE:  --min-size 0 added to block attempting to overwrite Google Doc files which have size -1 on Google Drive.  180729
        if rclone_cmd('copy', path2_base, path1_base, filter_file=user_filter_file, options=switches + ['--min-size', '0']):
            return RTN_CRITICAL
        logging.info(">>>>> --first-sync generating lsl files")
        if rclone_lsl(path1_base, path1_lsl_file, filter_file=user_filter_file):
            return RTN_CRITICAL
        if rclone_lsl(path2_base, path2_lsl_file, filter_file=user_filter_file):
            return RTN_CRITICAL

This is much simpler, there is no need to read 2 times LSL files and to loop for missing Path2 files, and the result should be the same. Am i missing something?

cjnaz commented 3 years ago

Thanks Eric. The command line doc error is a remnant from the algo rework in V3.0. With regard to the first-sync algo, you are probably correct, and as noted this should eliminate two LSL reads. I'll incorporate this change in the next rev, after I think carefully about any corner cases.

cjnaz commented 3 years ago

V3.2 released. Corrected the command line doc info, but deferred the first-sync optimization for now, since its not broke and should be rarely run. I'll leave this open, tagged for future enhancement.