首页 > 解决方案 > rsync only 文件夹,里面没有文件,也没有扫描文件

问题描述

我想使用 rsync 仅在文件夹 a 和 b 之间同步文件夹

> rsync -zaSH --delete -vv --delete -f"+ f/" -f"- f/*" a/ b
sending incremental file list
[sender] showing directory f because of pattern f/
[sender] hiding file f/1.data because of pattern f/*
[sender] hiding file f/4.data because of pattern f/*
[sender] hiding file f/8.data because of pattern f/*
[sender] hiding file f/10.data because of pattern f/*
[sender] hiding file f/6.data because of pattern f/*
[sender] hiding file f/3.data because of pattern f/*
[sender] hiding file f/5.data because of pattern f/*
[sender] hiding file f/9.data because of pattern f/*
[sender] hiding file f/7.data because of pattern f/*
[sender] hiding file f/2.data because of pattern f/*
delta-transmission disabled for local transfer or --whole-file
f/
total: matches=0  hash_hits=0  false_alarms=0 data=0

sent 88 bytes  received 90 bytes  356.00 bytes/sec
total size is 0  speedup is 0.00

> tree 
.
├── a
│   └── f
│       ├── 10.data
│       ├── 1.data
│       ├── 2.data
│       ├── 3.data
│       ├── 4.data
│       ├── 5.data
│       ├── 6.data
│       ├── 7.data
│       ├── 8.data
│       └── 9.data
└── b
    └── f

从详细输出中可以看出,文件仍然被扫描。如果文件夹中有数百万个文件可能需要很长时间。有没有办法在不扫描文件的情况下实现相同的目标?谢谢。

标签: linuxbashrsync

解决方案


你不能停止它直接扫描里面的文件a/f/,但它不应该扫描这些文件的任何子目录,除非它们也被调用f

此命令也将排除那些:

rsync -aSH --delete -vv --delete -f"+ /f/" -f"- /f/*" a/ b/

带有前缀的模式与/源目录的根匹配。

(我也删除了-z,因为压缩对本地副本没有意义。)


推荐阅读