返回

rclone 过滤,包含和排除规则

   
摘要GPT
摘要小助理暂时失联跑路啦……😜

文档:资料

文件类型过滤

比如 --exclude "*.bak",表示排除所有 .bak 结尾的文件,也可以写作 --filter "- *.bak"

比如 --include "*.{png,jpg}",包含所有 pngjpg 文件,排除其他文件,也可以写作 --filter "+ *.{png,jpg}"

--delete-excluded 删除排除的文件。需配合过滤参数使用,否则无效。

目录过滤

目录过滤需要在目录名称后面加上 /,否则会被当做文件进行匹配。以 / 开头只会匹配根目录(指定目录下),否则匹配所目录。这同样适用于文件。

--exclude ".git/" 排除所有目录下的.git 目录。

--exclude "/.git/" 只排除根目录下的.git 目录。

--exclude "{Video,Software}/" 排除所有目录下的 VideoSoftware 目录。

--exclude "/{Video,Software}/" 只排除根目录下的 VideoSoftware 目录。

--include "/{Video,Software}/**" 仅包含根目录下的 VideoSoftware 目录的所有内容。

大小过滤

默认大小单位为 kBytes ,但可以使用 kMG 后缀。

--min-size 过滤小于指定大小的文件。比如 --min-size 50 表示不会传输小于 50k 的文件。

--max-size 过滤大于指定大小的文件。比如 --max-size 1G 表示不会传输大于 1G 的文件。

过滤规则来自某个文件

--exclude-from <规则文件> :从文件添加包含规则

--include-from <规则文件>:从文件添加删除规则

--filter-from <规则文件> :从文件添加包含 / 排除规则。比如 --filter-from filter-file.txt

filter-file.txt 示例:

- secret*.jpg 
+ *.jpg
+ *.png
+ file2.avi
- /dir/Trash/**
+ /dir/**
- *

最佳实践

rclone sync D:\blog oss:tvcdn\blog -u -v -P --transfers=20 --ignore-errors --buffer-size=128M --check-first --checkers=10 --drive-acknowledge-abuse --exclude "/{.git,public,resources}/" --exclude "*.mp4"

这段代码的意思是:

序号操作命令
1同步本地文件夹 D:\blog 到远程 oss:tvcdn\blogrclone sync D:\blog oss:tvcdn\blog
2忽略已存在文件(此参数慎重)--ignore-existing
3仅更新新文件-u
4显示详细进度-v -P
5并发传输数量为 20--transfers=20
6忽略错误--ignore-errors
7缓冲大小为 128M--buffer-size=128M
8在首次同步前检查文件列表--check-first
9使用 10 个检查线程--checkers=10
10启用 Google Drive 滥用确认--drive-acknowledge-abuse
11排除 .gitpublicresources 文件夹--exclude "/{.git,public,resources}/"
12排除所有 *.mp4 文件--exclude "*.mp4"
知识共享许可证 CC BY-NC-SA 4.0
最后更新于 2024-07-17 18:28
使用 Hugo 构建
主题 hugo-magic小洋葱 魔改 由 Jimmy 设计
Written by Human, Not by AI