2

I would like to use rsync to download specific files from a server, here are the scheme of the directory:

. 
file1
fakeotherfolder
   filefile
   morefile
   morefakefolder
      file
file2
file3
mainfolder
   myfolder1
      folfile1
      folfile2
   myfolder2
      folfile1
      folfile2
   myfolder3
      folfile1
      folfile2
   myfolder4
      folfile1
      folfile2

Basically I would like to get ALL the files that are NOT in a mainfolder/myfolder* except the specific mainfolder/myfolder2 for exemple.

What I want at the end:

 . 
file1
fakefolder
   filefile
   morefile
   morefakefolder
      file
file2
file3
mainfolder
   myfolder2
      folfile1
      folfile2

I tried rsync with the following options:

rsync --include="*/mainfolder/myfolder2/*" --exclude="*/mainfolder/*"

but what I get is an empty mainfolder...

 . 
file1
fakefolder
   filefile
   morefile
   morefakefolder
      file
file2
file3
mainfolder
4

1 回答 1

3

什么地方出了错

rsync --include="*/mainfolder/myfolder2/*" --exclude="*/mainfolder/*"
  1. 该指令--include="*/mainfolder/myfolder2/*"告诉rsync包含目录下的文件*/mainfolder/myfolder2/。您可能认为它应该隐含地告诉它包含目录*/mainfolder/myfolder2/,但事实并非如此。它只包括该目录下的文件。

  2. 该指令--exclude="*/mainfolder/*"告诉它排除*/mainfolder. 这意味着它排除了*/mainfolder/myfolder2/. 因为 myfolder2 被排除在外,所以永远不会检查它下面的文件。

如何修复它

解决方案是明确包括mainfolder/myfolder2

rsync --include="mainfolder/myfolder2" --include="mainfolder/myfolder2/*" --exclude="mainfolder/*" src/ dest

解决方案是明确包括mainfolder/myfolder2

请注意,resync解释包含/排除它们的顺序。因此,重要的是--include="mainfolder/myfolder2"出现在 之前--exclude="mainfolder/*"。总之,我们需要三个指令,并且 exclude 指令需要放在最后:

  1. --include="mainfolder/myfolder2"

  2. --include="mainfolder/myfolder2/*"

  3. --exclude="mainfolder/*"

于 2014-10-11T05:45:27.990 回答