Include some directories, exclude all other directories, filter some directories

Sorry for the confusing title, but I'm using rclone to back up 2 critical folders on the root of my drive:

  • /opt
  • /root

In the future I will need to add more, but for now, those two are the most critical.

So I initially decided to use --include-from. But then I needed to exclude certain directories inside /root, so I thought about using --exclude-from as well. This is not recommended per the docs, so I moved on to --filter-from.

Here's what I have so far:

> rclone sync / gdrive-opt: --track-renames --copy-links --log-level INFO --log-file /path/to/log --drive-use-trash --filter-from /path/to/filter.list --dry-run

Here's the filter.list

# Filter list for root backup
# Baseline, exclude all directories
- /**
# But only backup these matches
+ /opt/**
+ /root/**
# and exclude these
- /root/path/to/excludedfolder/**

But this basically matched the first rules and then stopped processing the rest. How can i accomplish this process of including only specified directories and excluding some directories below those included directories?

1 Like

Change the order to match the most restrictive first and go top down.

So I think:

# Filter list for root backup
- /root/path/to/excludedfolder/**
# But only backup these matches
+ /opt/**
+ /root/**
# Baseline, exclude all directories
- /**

Test the command with a rclone ls command see if the output is correct.

1 Like

I think this worked. The output from a --dry-run appeared to only return the folder/files I wanted it to return.

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