Skip to main content

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.

Learning Focus

Build filter rules you can trust, then test them with dry-runs before you rely on them in automation.

Rule Basics

FlagPurpose
--excludeOmit matching files/directories
--includeAllow specific files/directories
--exclude-fromLoad excludes from file
--include-fromLoad includes from file
--filterAdvanced rule engine

Flag Deep Dives

Use these focused docs when you want exact behavior per flag:

For production jobs:

  1. Put rules into files (/etc/rclone/*.filter).
  2. Apply them consistently across scripts.
  3. Validate with --dry-run -vv whenever rules change.

Practical Command

filtered-sync.sh
rclone sync /srv/app remote-prod:backups/app \
--exclude "**/.git/**" \
--exclude "**/node_modules/**" \
--exclude "**/*.log" \
--progress
warning

Do not forget secrets. Add .env, private keys, and credential files to your exclude list.

Pattern File Example

/etc/rclone/app.exclude
**/.git/**
**/node_modules/**
**/*.log
**/.env
rclone sync /srv/app remote-prod:backups/app --exclude-from /etc/rclone/app.exclude
tip

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:

/etc/rclone/app.filter
# 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
note

Order matters. More specific allow rules should appear before broader deny rules.

Common Pitfalls

PitfallOutcomePrevention
Over-broad wildcardNeeded files are skippedTest with --dry-run -vv
Missing recursive patternNested files still transferUse ** where required
Filtering only source side assumptionsUnexpected remote stateReview behavior with sync vs copy

Hands-On Practice

  1. Create a filter file.
  2. Run a dry-run copy and confirm excluded files do not appear.
practice-filters.sh
cat > /tmp/rclone.filter <<'EOF'
+ **/*.md
+ **/*.mdx
- **
EOF

rclone copy /srv/docs remote-prod:labs/docs --filter-from /tmp/rclone.filter --dry-run -vv

What's Next