Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 如何从两台服务器上都存在的rsync中排除目录?_Linux_Bash_Rsync - Fatal编程技术网

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

Linux 如何从两台服务器上都存在的rsync中排除目录?,linux,bash,rsync,Linux,Bash,Rsync,以下是我的文件结构: Server_A Server_B ============== ============== /path/dir1/ /path/dir1/ logA.txt logA.txt logB.txt logB.txt /path/dir2/ /path/d

以下是我的文件结构:

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
我需要rsync path/dir2从服务器A到B,而不是path/dir1

我的rsync命令如下所示:

rsync -arv --exclude '/dir1' /path/ root@server_b:/path
/tmp/src/
/tmp/src/dir1
/tmp/src/dir1/file1
/tmp/src/dir1/file2
/tmp/src/dir2
/tmp/src/dir2/file1
/tmp/src/dir2/file2
rsync -av --exclude=/dir1 /tmp/src/ server:/tmp/dst/
sending incremental file list
created directory /tmp/dst
./
dir2/
dir2/file1
dir2/file2
但每次我运行它,结果都会在打印输出中显示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
,如下所示:

rsync -arv --exclude '/dir1' /path/ root@server_b:/path
/tmp/src/
/tmp/src/dir1
/tmp/src/dir1/file1
/tmp/src/dir1/file2
/tmp/src/dir2
/tmp/src/dir2/file1
/tmp/src/dir2/file2
rsync -av --exclude=/dir1 /tmp/src/ server:/tmp/dst/
sending incremental file list
created directory /tmp/dst
./
dir2/
dir2/file1
dir2/file2
我可以将它同步到另一台服务器,并排除
/tmp/src/dir1
,如下所示:

rsync -arv --exclude '/dir1' /path/ root@server_b:/path
/tmp/src/
/tmp/src/dir1
/tmp/src/dir1/file1
/tmp/src/dir1/file2
/tmp/src/dir2
/tmp/src/dir2/file1
/tmp/src/dir2/file2
rsync -av --exclude=/dir1 /tmp/src/ server:/tmp/dst/
sending incremental file list
created directory /tmp/dst
./
dir2/
dir2/file1
dir2/file2
跑步过程如下所示:

rsync -arv --exclude '/dir1' /path/ root@server_b:/path
/tmp/src/
/tmp/src/dir1
/tmp/src/dir1/file1
/tmp/src/dir1/file2
/tmp/src/dir2
/tmp/src/dir2/file1
/tmp/src/dir2/file2
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命令行和文件系统。如果看不到任何明显的内容,可以发布正在运行的实际命令以及顶级目录列表(除非它很大)