bash - 嵌套的 rsync --include 和 --exclude 规则,是否应该通过多个命令来实现?

标签 bash unix rsync

在 Web 服务器环境之间,我们的数据 Assets 文件夹结构类似于以下内容:

/Volumes/data-acct/assets/
├── audio
│   ├── section1
│   │   └── nested files and folders
│   └── section2
├── css
│   ├── section1
│   │   └── nested files and folders
│   └── section2
├── images
│   ├── section1
│   │   └── nested files and folders
│   └── section2
└── videos
    ├── section1
    └── section2

我一直在尝试找到一个包含过滤器,它允许我为每个区域匹配特定的部分文件夹,尽管从 --include="*/"更改时没有得到任何结果 (包含所有文件夹和 --include="*/section1/**/*.*"

rsync --dry-run --verbose --recursive --update --include="*/section1/**/*.*" --exclude="*" /Volumes/data-acct/assets/ /Volumes/data-live/assets/

我应该为此运行多个命令吗?或者我应该使用 --filters 参数(似乎没有记录)

最佳答案

我确信仅使用 rsync 就有一个很好的解决方案(因为它非常强大),但当有疑问时,我喜欢依靠像这样的众所周知的工具:

cd /Volumes/data-acct/assets &&
find . |            # get all files
  grep /section1/ | # that contain section1
  grep -v videos/ | # but without videos
  rsync --dry-run --verbose --recursive --update --files-from=- \
    /Volumes/data-acct/assets/ /Volumes/data-live/assets/

--files-from 选项允许您创建自己的自定义列表,而无需使用任何 rsync 过滤器。

关于bash - 嵌套的 rsync --include 和 --exclude 规则,是否应该通过多个命令来实现?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23681752/

相关文章:

bash - 如何比较bash脚本中文件的时间戳

bash - 第三方二进制文件应该安装在 UNIX 系统上的哪里?

linux - 如何使 GNU Parallel 使用记录分隔符从多个文件中获取输入

command-line - 使用 SSH/命令行 FTP 传输服务器到服务器

android - 为 Android 构建 Rsync

linux - shell 内的 shell 脚本 shell

linux - 如何检查手册页是否存在?

c - 以编程方式并行化 C 程序的一部分

Java 迭代日期对象的数组列表并将每个日期转换为其unix时间戳

linux - rsync 和 --link-dest 的磁盘使用问题