如何rsync的文件,通过保持目录结构不变匹配路径模式? [英] How to rsync files with matching pattern in path by keeping directory structure intact?

查看:1067
本文介绍了如何rsync的文件,通过保持目录结构不变匹配路径模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要复制从服务器A到服务器B有不同层次的文件系统层次结构,例如同一父目录名的所有文件:

I want to copy all files from server A to server B that have the same parent directory-name in different levels of filesystem hierarchy, e.g:

/var/lib/data/sub1/sub2/commonname/filetobecopied.foo
/var/lib/data/sub1/sub3/commonname/filetobecopied.foo
/var/lib/data/sub2/sub4/commonname/anotherfiletobecopied.foo
/var/lib/data/sub3/sub4/differentname/fileNOTtobecopied.foo

我想前三个文件都具有通用名称的路径服务器B.我已经找到了正确的花了大量的时间包含/排除的模式复制为的rsync ,但我不明白这一点。下面的命令不起作用:

I want to copy the first three files that all have the commonname in path to server B. I already spent a lot of time in finding the correct include/exclude patterns for rsync but I dont get it. The following command does not work:

rsync -a --include='**/commonname/*.foo' --exclude='*' root@1.2.3.4:/var/lib/data /var/lib/data

我要么比赛太多或几个文件。我怎样才能在其路径只同步与通用名称文件?

推荐答案

我猜你正在寻找这样的:

I guess you're looking for this:

rsync -a -m --include='**/commonname/*.foo' --include='*/' --exclude='*' root@1.2.3.4:/var/lib/data /var/lib/data

有2分歧与您的命令:


  • 其中最重要的是 - 包括= * / 。如果没有这一点,因为你指定的 - 排除='*'的rsync 将不会进入子目录,因为一切都排除。随着 - 包括= * / 的子目录不再排斥,所以的rsync 能够愉快递归

  • 最不重要的是 -m :此修剪空目录。没有这一点,你想也得到(空)子目录的/ var / lib中/数据/ SUB3 / SUB4 / differentname / 复制。

  • The most important one is --include='*/'. Without this, as you specified --exclude='*', rsync will never enter the subdirectories, since everything is excluded. With --include='*/', the subdirectories are not excluded anymore, so rsync can happily recurse.
  • The least important one is -m: this prunes the empty directories. Without this, you'd also get the (empty) subdirectory /var/lib/data/sub3/sub4/differentname/ copied.

这篇关于如何rsync的文件,通过保持目录结构不变匹配路径模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆