从文件读取input并相应地进行同步
我有一个文本文件,其中包含我想要复制的文件和目录列表(一行一行)。 现在我想让rsync从我的文本文件中获取这个input,并将其同步到我提供的目的地。
我试着玩"--include-from=FILE"和"--file-from=FILE"选项的rsync,但它只是不工作 
 我也尝试在我的文件中的每一行预固定"+" ,但仍然无法正常工作。 
我已经尝试过在rsync手册页列出的各种filter模式,但它仍然无法正常工作。
有人可以为我提供这个用例的正确语法。 我已经尝试了上面的Fedora 15,RHEL 6.2和Ubuntu 10.04上的东西,没有任何工作。 所以我肯定错过了一些东西。
非常感谢。
根据您想要如何复制这些文件,有多种方法可以回答此问题。 如果你的意图是复制绝对path的文件列表,那么它可能看起来像这样:
 rsync -av --files-from=/path/to/files.txt / /destination/path/ 
  …这将期望path相对于/的源位置,并将保留在该目的地下的整个绝对结构。 
如果您的目标是将列表中的所有文件复制到目标,而不保留任何types的path层次结构(只是一组文件),则可以尝试以下方法之一:
 # note this method might break if your file it too long and # exceed the maximum arg limit rsync -av `cat /path/to/file` /destination/ # or get fancy with xargs to batch 200 of your items at a time # with multiple calls to rsync cat /path/to/file | xargs -n 200 -J % rsync -av % /destination/ 
或者for循环和复制:
 # bash shell for f in `cat /path/to/files.txt`; do cp $f /dest/; done 
给定一个包含$ HOME / GET / bringemback的文件
 **need/A alsoneed/B shouldget/C** 
cd $ HOME / GET
跑
 rsync -av --files-from=./bringemback me@theremote:. $HOME/GET/collect 
 会得到这些文件,并把它们放到$HOME/GET/collect 
 $HOME/GET/ collect/ need/A alsoneed/B shouldget/C 
或者我相信。
有帮助
rsync本地支持:
 rsync --recursive -av --files-from=/path/to/files.txt / /destination/path/