cjnaz / rclonesync-V2

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

possible to use `--exlude-if-present` rclone arg? #76

Closed rinkjames closed 2 years ago

rinkjames commented 2 years ago

The reason I ask is because, as far as I understand, filter-from using a filters file such as the one below doesn't permit me to exclude a directory and its contents recursively based on the file name of a file it might contain. This apparently is exaclty what --exlude-if-present is used for. I tried adding it at the end of a rclonesync command but it didn't recognise it, e.g. --rclone-args --exlude-if-present .git.

# Filter file for use with rclonesync
# See https://rclone.org/filtering/ for filtering rules
# NOTICE:  If you make changes to this file you MUST do a --first-sync run.  Run with --dry-run to see what changes will be made.

- .DS_Store
- desktop.ini
- Icon?
- .localized
- $RECYCLE.BIN/
- ~$*
- *(nosync)/
- .git/
- .Rproj.user/
- renv/library/
- renv/local/
- renv/lock/
- renv/python/
- renv/staging/
- */.git
+ **

Is there any other way to filter directories in this manner with reclonesync?

cjnaz commented 2 years ago

If you are trying to exclude .git dirs throughout your sync tree try adding this in your filters file:

- .git/**

Does this do it, or are you looking for something else?

rinkjames commented 2 years ago

No, so I'm trying to exclude all directories that contain .git directories, just as an example.

cjnaz commented 2 years ago

I see. Like a .nomedia file flag. A quick look at the code shows that the rclone-args are passed to the rclone LSL calls which are the basis for all possible files to sync. Try --exclude-if-present on direct rclone lsl calls to see if it behaves as you need. Please share your results.

Note that rclonesync is being incorporated in rclone in an upcoming release - beta version. I'm not currently planning on feature additions for rclonesync as it will soon be absorbed into rclone proper.

rinkjames commented 2 years ago

Re. the beta release — very exciting and I've been keeping an eye on rclone updates. If this doesnt work somehow out of the box with rclonesync right now, that's fine. I'll wait for rclone to integrate reclonesync and reassess then.

Re. trying --exclude-if-present, I don't know if I'm doing this correctly.

Both this:

rclonesync  ~/Google\ Drive \
            gdrive:drive \
            -evc \
            --check-filename .rclonesync-check-access-file \
            -f ~/.rclonesyncwd/filters1 \
            --rclone-args --exlude-if-present .git

...and this:

rclonesync  ~/Google\ Drive \
            gdrive:drive \
            -evc \
            --check-filename .rclonesync-check-access-file \
            -f ~/.rclonesyncwd/filters1 \
            --rclone-args "--exlude-if-present .git"

...return this:

>>>>> Path1 Checking for Diffs
Error: unknown flag: --exlude-if-present
Usage:
  rclone lsl remote:path [flags]

Flags:
  -h, --help   help for lsl

Use "rclone [command] --help" for more information about a command.
Use "rclone help flags" for to see the global flags.
Use "rclone help backends" for a list of supported services.
cjnaz commented 2 years ago

Try --exclude-if-present with a c. :>

rinkjames commented 2 years ago

Wow that's embarrassing. ~It work now. lol~

rinkjames commented 2 years ago

So I tested this a little more thouroughly and rclonesync works with the (properly spelled) --exclude-if-present rclone argument, but only on first sync and/or when there are no differences between path1 and path2. If there's a difference to be synced and --exclude-if-present is included, I get the following error:

rclonesync  ~/Documents gdrive:docs.rinkjames/Documents \
            -evc \
            --check-filename .rclonesync-check-access-file \
            -f ~/.rclonesyncwd/filters \
            --rclone-args --exclude-if-present .nosync \
            >> ~/.rclonesyncwd/log_documents 2>&1
2021-10-23 17:10:14,237:    Path1      Do queued copies to               - Path2
2021/10/23 17:10:14 Failed to load filters: The usage of --files-from-raw overrides all other filters, it should be used alone or with --files-from
2021/10/23 17:10:14 Failed to load filters: The usage of --files-from-raw overrides all other filters, it should be used alone or with --files-from
2021/10/23 17:10:14 Failed to load filters: The usage of --files-from-raw overrides all other filters, it should be used alone or with --files-from
2021-10-23 17:10:14,348:    ERROR    rclone copy failed.  (Line 469)     - /Users/rinkjames/Documents/
2021-10-23 17:10:14,348:  Lock file removed: </var/folders/6z/ld9v651j0q3c6f0s_sp5tz6h0000gn/T/rclonesync_LOCK__Users_rinkjames_Documents_gdrive_docs.rinkjames_Documents_>
2021-10-23 17:10:14,348:  ***** Critical Error Abort - Must run --first-sync to recover.  See README.md *****

I tried passing the filter file as an rclone argument as well with --rclone-args --exclude-from ~/.rclonesyncwd/filters --exclude-if-present .nosync, but results in the same error. Any suggestions?

cjnaz commented 2 years ago

It's erroring on the queued copy and delete commands. Within rclonesync, the exclude if present would only be needed on the LSL calls. To do it right the --exclude-if-present needs to be removed from the queued copy and delete commands where --files-from-raw is used.

For your case, you can try commenting out lines 601 and 602 (V3.2), assuming you are not using any other supplemental rlcone args.

rinkjames commented 2 years ago

Thanks for the suggestion re lines 601-602. I couldn't get this to work though. Other issues started popping up with removing directories and first-syncs ignoring the --exclude-if-present flag. I'll resort to appending no-sync to folder names and using a - *no-sync/ rule in the filters file. Maybe I can get this working once rclonesync is fully integrated into rclone.