linux - 如何从 rsync 中排除两台服务器上都存在的目录?

标签 linux bash rsync

这是我的文件结构:

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/

相关文章:

linux - Bash 终端 - .profile 不调用终端中的某些函数

bash - 在 bash 中搜索 .netrc 文件,并返回给定机器的用户名

Linux:使用 lsyncd 同步多个服务器上的多个文件夹

python - 监控 Rsync 进度

linux - 是否有 linux 命令阻塞直到进程退出?

python + 如何在 python 中验证 linux 命令是否成功

Linux 上的 Python 远程连接到 Windows PC 以检索文件

python - 有谁知道我可以在哪里获得适用于 azure 的 linux python SDK?

bash - 防止从 Bash 中的源文件执行命令

linux - rsync 使用包含选项仅复制某些类型的文件