如何将目录和文件从源同步到目标

如何将目录和文件从源同步到目标

如何使用“rsync”将目录和文件(某些类型除外)复制到目的地?以下是要豁免或不同步的文件类型; *.odb、*.a3db

答案1

您可以使用 rsync 过滤器功能。例如使用以下命令:

rsync -uva --filter="- *.odb" --filter="- *.a3db" /source-path/ /destination-path/

答案2

使用一些排除模式:

rsync -av --exclude='*.odb' --exclude='*.a3db' source/ target/

例子:

$ ls source
file-1.a3db  file-2.odb   file-4.a3db  file-5.odb   file-7.a3db  file-8.odb
file-1.c     file-2.txt   file-4.c     file-5.txt   file-7.c     file-8.txt
file-1.odb   file-3.a3db  file-4.odb   file-6.a3db  file-7.odb   file-9.a3db
file-1.txt   file-3.c     file-4.txt   file-6.c     file-7.txt   file-9.c
file-2.a3db  file-3.odb   file-5.a3db  file-6.odb   file-8.a3db  file-9.odb
file-2.c     file-3.txt   file-5.c     file-6.txt   file-8.c     file-9.txt

使用-v两次,我们可以得到包含和排除的内容的指示:

$ rsync -avv --exclude='*.odb' --exclude='*.a3db' source/ target/
sending incremental file list
[sender] hiding file file-1.odb because of pattern *.odb
[sender] hiding file file-1.a3db because of pattern *.a3db
[sender] hiding file file-2.odb because of pattern *.odb
[sender] hiding file file-2.a3db because of pattern *.a3db
[sender] hiding file file-3.odb because of pattern *.odb
[sender] hiding file file-3.a3db because of pattern *.a3db
[sender] hiding file file-4.odb because of pattern *.odb
[sender] hiding file file-4.a3db because of pattern *.a3db
[sender] hiding file file-5.odb because of pattern *.odb
[sender] hiding file file-5.a3db because of pattern *.a3db
[sender] hiding file file-6.odb because of pattern *.odb
[sender] hiding file file-6.a3db because of pattern *.a3db
[sender] hiding file file-7.odb because of pattern *.odb
[sender] hiding file file-7.a3db because of pattern *.a3db
[sender] hiding file file-8.odb because of pattern *.odb
[sender] hiding file file-8.a3db because of pattern *.a3db
[sender] hiding file file-9.odb because of pattern *.odb
[sender] hiding file file-9.a3db because of pattern *.a3db
delta-transmission disabled for local transfer or --whole-file

(其余减产)

$ ls target
file-1.c   file-2.txt file-4.c   file-5.txt file-7.c   file-8.txt
file-1.txt file-3.c   file-4.txt file-6.c   file-7.txt file-9.c
file-2.c   file-3.txt file-5.c   file-6.txt file-8.c   file-9.txt

即使文件位于source.

相关内容