How to specify what folders to sync and what to exclude -- include, exclude, filter?

I have an arbitrary # of folders I want to backup to the cloud, and, for each folder I have specific things I want to exclude.

With rsync I am using using / as the source and then --files-from and --exclude-from:





I thought I could use the same flags with rclone but reading, I am not sure if --files-from and --exclude-from can be used together?

Would I use --files-from and --exclude-from just like I am with rsync:


Or would I have to use --filter:

    --filter="+ /home"
    --filter="+ /etc"
    --filter="+ /stuff"
    --filter="- /home/*/.tmp"
    --filter="- /home/*/.cache"
    --filter="- /stuff/lost+found"

Or is there a better way to do this?

I'd make a filter file and clean it up a little bit. You match top down, so you want to be most specific to least specific kind of like a firewall rule.

I think I did something similar to what you are asking but hard to be sure I got your rules translated in my brain right.

felix@gemini:~/test$ rclone ls /home/felix/test --filter-from filter
       84 filter
        0 home/test
        0 stuff/adfjad
        0 notme/aalkdfjaf
felix@gemini:~/test$ rclone ls /home/felix/test
       84 filter
        0 stuff/adfjad
        0 home/test
        0 notme/aalkdfjaf
        0 home/.tmp/blah
felix@gemini:~/test$ cat filter
- /home/.tmp/**
- /home/.cache/**
- /stuff/lost+found
+ home/**
+ etc/**
+ stuff/**

That gives you an idea. I always test with rclone ls and do a --dry-run after to ensure it will do what I expect and then actually run the copy or sync command.

1 Like

Thanks but I'm still not getting something.

If I run rlcone ls / I get thousands of files, all of the files on my system.

If I run rclone ls / --filter="+ /home/**" I would expect it to just include files in my /home but it is still returning all files in my system.

If I do a sync, I would need to do it from / because the files I want to sync are in different places on my system.

You'd want to add the exclude at the end in that example.

rclone ls / --filter='+ /home/**'  --filter='- *'

I find a file to be easier for me.


Thanks. That solves me.

I am creating the filter list dynamically, in a script, and I don't want to create a temp file. I got this working:

INCLUDES=('/home/**' '/etc/**' '/stuff/**')
EXCLUDES=('/home/*/.gvfs/**' '/home/*/.cache/**' '/home/*/.local/share/Trash/**' '/home/*/.vscode-server/**' '/stuff/lost+found/**')

set -o noglob
        for option in ${EXCLUDES[@]};
            echo --filter="- $option" >> "$LOG_FILE"
            filterOptions+=(--filter="- $option")

        for option in ${INCLUDES[@]};
            echo --filter="- $option" >> "$LOG_FILE"
            filterOptions+=(--filter="+ $option")
        echo --filter="- /**" >> "$LOG_FILE"
        filterOptions+=(--filter="- /**")
set +o noglob

/usr/bin/rclone                                            \
        --dry-run                                          \
        -v                                                 \
        --fast-list                                        \
        --skip-links                                       \
        --config="/root/.config/rclone/rclone.conf"        \
        "${filterOptions[@]}"                              \
        --backup-dir "remote:old"                          \
        --suffix ".$(/bin/date +\%Y\%m\%d\%H\%M\%S)"       \
        sync                                               \
            /                                              \
            "remote:new"                                   \
        >> "$LOG_FILE"                                     \



This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.