这是我的文件结构:
Server_A Server_B
============== ==============
/path/dir1/ /path/dir1/
logA.txt logA.txt
logB.txt logB.txt
/path/dir2/ /path/dir2/
fileC.txt fileC.txt
fileD.txt fileC.txt
我需要将 path/dir2 从服务器 A 同步到 B,但不需要同步 path/dir1。
我的 rsync 命令如下所示:
rsync -arv --exclude '/dir1' /path/ root@server_b:/path
但是每次我运行它时,结果都会在打印输出中显示 dir1:
sending incremental file list
./
dir1/
dir1/logA.txt
dir1/logB.txt
sent 52147 bytes received 23342 bytes 14405.50 bytes/sec
total size is 215619123 speedup is 2851.02
我错过了什么?
最佳答案
我不相信您已经准确地转录了您正在运行的命令。如果我有一个如下所示的目录 /tmp/src
:
/tmp/src/
/tmp/src/dir1
/tmp/src/dir1/file1
/tmp/src/dir1/file2
/tmp/src/dir2
/tmp/src/dir2/file1
/tmp/src/dir2/file2
我可以将其同步到另一台服务器 - 并排除 /tmp/src/dir1
- 像这样:
rsync -av --exclude=/dir1 /tmp/src/ server:/tmp/dst/
运行看起来像这样:
sending incremental file list
created directory /tmp/dst
./
dir2/
dir2/file1
dir2/file2
这似乎与您在问题中所描述的完全匹配。我正在使用 rsync 版本 3.0.8。我建议仔细检查您的实际 rsync 命令行和文件系统。如果您没有看到任何明显的内容,您可以发布您正在运行的实际命令以及顶级目录列表(除非它很大)吗?
关于linux - 如何从 rsync 中排除两台服务器上都存在的目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10542073/