ssh上的递归rsync,只包含一个文件扩展名

时间:2015-05-18 16:14:20

标签: ssh rsync

我试图通过ssh将文件从服务器rsync到我的机器。文件位于各个子目录中,但我只想保留与某个模式匹配的文件(IE blah .txt)。我已经在stackoverflow上进行了大量的谷歌搜索和搜索,并且我已经尝试了几乎所有已经建议的--include和--excludes的排列。无论我尝试什么,rsync都会抓取所有文件。 作为我的一个尝试的例子,我使用过: rsync -avze 'ssh' --include='*blah*.txt' --exclude='*' myusername@myserver.com:/path/top/files/directory /path/to/local/directory

要进行故障排除,我尝试了以下命令: rsync -avze 'ssh' --exclude='*' myusername@myserver.com:/path/top/files/directory /path/to/local/directory 期望它不会复制任何东西,但它仍然抓住了所有文件。

我在OSX上使用rsync版本2.6.9。

有什么明显的东西我不见了吗?我已经挣扎了很长一段时间。

2 个答案:

答案 0 :(得分:3)

我能找到一个解决方案,但需要注意。这是工作命令: rsync -vre 'ssh' --prune-empty-dirs --include='*/' --include='*blah*.txt' --exclude='*' user@server.com:/path/to/server/files /path/to/local/files

然而!如果我直接在命令行中键入它,它就可以工作。如果我将它保存到文件myfile.txt,我尝试`cat myfile.txt`它不再有效!这对我来说毫无意义。

答案 1 :(得分:0)

OSX遵循BSD样式rsync

https://www.freebsd.org/cgi/man.cgi?query=rsync&apropos=0&sektion=0&manpath=FreeBSD+8.0-RELEASE+and+Ports&format=html

-C, - cvs-exclude           这是排除大量文件的有用简写           您经常不想在系统之间转移。它使用了           类似于CVS的算法,以确定文件是否应该           忽略。

      The exclude list is initialized to exclude the  following  items
      (these  initial items are marked as perishable -- see the FILTER
      RULES section):

         RCS  SCCS  CVS  CVS.adm   RCSLOG   cvslog.*   tags   TAGS
         .make.state  .nse_depinfo *~ #* .#* ,* _$* *$ *.old *.bak
         *.BAK *.orig *.rej .del-* *.a *.olb *.o *.obj *.so  *.exe
         *.Z *.elc *.ln core .svn/ .git/ .bzr/

      then,  files  listed in a $HOME/.cvsignore are added to the list
      and any files listed in the CVSIGNORE environment variable  (all
      cvsignore names are delimited by whitespace).

      Finally, any file is ignored if it is in the same directory as a
      .cvsignore file and matches one of the patterns listed  therein.
      Unlike rsync's filter/exclude files, these patterns are split on
      whitespace.  See the cvs(1) manual for more information.

      If you're combining -C with your own --filter rules, you  should
      note that these CVS excludes are appended at the end of your own
      rules, regardless of where the -C was  placed  on  the  command-
      line.  This makes them a lower priority than any rules you spec-
      ified explicitly.  If  you  want  to  control  where  these  CVS
      excludes  get  inserted  into your filter rules, you should omit
      the -C as a command-line option and use a combination of  --fil-
      ter=:C  and  --filter=-C  (either  on  your  command-line  or by
      putting the ":C" and "-C" rules into a  filter  file  with  your
      other rules).  The first option turns on the per-directory scan-
      ning for the .cvsignore file.  The second option does a one-time
      import of the CVS excludes mentioned above.

   -f, --filter=RULE
      This  option allows you to add rules to selectively exclude cer-
      tain files from the list of files to  be  transferred.  This  is
      most useful in combination with a recursive transfer.

      You  may use as many --filter options on the command line as you
      like to build up the list of files to exclude.   If  the  filter
      contains whitespace, be sure to quote it so that the shell gives
      the rule to rsync as a single argument.   The  text  below  also
      mentions  that  you  can  use an underscore to replace the space
      that separates a rule from its arg.

      See the FILTER RULES section for detailed  information  on  this
      option.