Include and Exclude Patterns
Include/exclude controls are the foundation of precise transfer scope in rclone. This section explains how to design rule sets that are readable, testable, and safe for automation so you can avoid copying noise, prevent accidental omissions, and keep backup behavior consistent across environments.
Build filter rules you can trust, then test them with dry-runs before you rely on them in automation.
Rule Basics
| Flag | Purpose |
|---|---|
--exclude | Omit matching files/directories |
--include | Allow specific files/directories |
--exclude-from | Load excludes from file |
--include-from | Load includes from file |
--filter | Advanced rule engine |
Flag Deep Dives
Use these focused docs when you want exact behavior per flag:
Recommended Approach
For production jobs:
- Put rules into files (
/etc/rclone/*.filter). - Apply them consistently across scripts.
- Validate with
--dry-run -vvwhenever rules change.
Practical Command
rclone sync /srv/app remote-prod:backups/app \
--exclude "**/.git/**" \
--exclude "**/node_modules/**" \
--exclude "**/*.log" \
--progress
Do not forget secrets. Add .env, private keys, and credential files to your exclude list.
Pattern File Example
**/.git/**
**/node_modules/**
**/*.log
**/.env
rclone sync /srv/app remote-prod:backups/app --exclude-from /etc/rclone/app.exclude
Keep filter files versioned in infrastructure repos, but never commit secrets.
Advanced Filters (Rule Files)
Rclone also supports filter rule files (ordered allow/deny rules). A common pattern:
# include only source code and configs
+ **/*.php
+ **/*.py
+ **/*.js
+ **/*.ts
+ **/*.json
+ **/*.yml
# deny everything else
- **
rclone copy /srv/app remote-prod:backups/app --filter-from /etc/rclone/app.filter --dry-run -vv
Order matters. More specific allow rules should appear before broader deny rules.
Common Pitfalls
| Pitfall | Outcome | Prevention |
|---|---|---|
| Over-broad wildcard | Needed files are skipped | Test with --dry-run -vv |
| Missing recursive pattern | Nested files still transfer | Use ** where required |
| Filtering only source side assumptions | Unexpected remote state | Review behavior with sync vs copy |
Hands-On Practice
- Create a filter file.
- Run a dry-run copy and confirm excluded files do not appear.
cat > /tmp/rclone.filter <<'EOF'
+ **/*.md
+ **/*.mdx
- **
EOF
rclone copy /srv/docs remote-prod:labs/docs --filter-from /tmp/rclone.filter --dry-run -vv