【问题标题】:rsync - exclude everything except a subdir, but exclude a sub subdirrsync - 排除除子目录之外的所有内容,但排除子子目录
【发布时间】:2018-06-21 14:50:37
【问题描述】:

我正在尝试将远程目录同步到本地,我想排除除子目录之外的所有内容。但是那个子目录里面有一个我想排除的子目录。我的理解是 rsync 在排除之后应用包含,我试图在这里找出必要的模式。这些是我传递的包含/排除标志:

rsync -Pav -e "ssh -i /path/to/key.pem" \
  --include="subdir/***" \
  --exclude="subdir/subsubdir" \
  --exclude="*" \
  remote@address.com:/path/to/remote/dir/ \
  /path/to/local/dir/

编辑:这目前导致 rsync 抓取子目录内的所有内容,包括我试图排除的子目录。

谢谢!

【问题讨论】:

  • 目前的行为是什么?
  • 获取子目录中的所有内容,包括排除的子目录
  • rsync 按照你给它们的顺序应用过滤器,所以在包含之前尝试 subsub exclude。
  • @meuh 好吧...就是这样:) 而且我还必须将斜杠添加到排除的子目录中。你想把它写成答案,我会标记它是正确的吗?

标签: bash rsync


【解决方案1】:

我对 rsync 应用过滤器的假设是错误的。 @meuh 留下了正确答案的评论:

rsync 按照你给它们的顺序应用过滤器,所以在包含之前尝试 subsub exclude。

我还必须在我的排除项中添加一个斜杠。这是正确的 rsync 命令:

rsync -Pav -e "ssh -i /path/to/key.pem" \
  --exclude="subdir/subsubdir/" \
  --include="subdir/***" \
  --exclude="*" \
  remote@address.com:/path/to/remote/dir/ \
  /path/to/local/dir/

这里是本地运行命令的演示:

rsync -Pav \
  --exclude="subdir/subsubdir/"
  --include="subdir/***" \
  --exclude="*" \
  ./remote/ \
  ./local/

之前:

.
├── local
└── remote
    ├── subdir
    │   ├── subsubdir
    │   │   └── test.txt
    │   └── test.txt
    └── test.txt

之后:

.
├── local
│   └── subdir
│       └── test.txt
└── remote
    ├── subdir
    │   ├── subsubdir
    │   │   └── test.txt
    │   └── test.txt
    └── test.txt

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-08
    • 1970-01-01
    • 2017-07-08
    • 1970-01-01
    • 1970-01-01
    • 2010-12-12
    相关资源
    最近更新 更多