如何从两个服务器上的rsync中排除目录?

时间:2021-08-18 07:31:36

Here's my file structure:

这是我的文件结构:

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

I need to rsync path/dir2 from server A to B, but not path/dir1.

我需要rsync path/dir2从服务器A到B,而不是路径/dir1。

My rsync command looks like this:

我的rsync命令如下:

rsync -arv --exclude '/dir1' /path/ root@server_b:/path

But every time I run it the result shows dir1 in the print out:

但是每次我运行它,结果在打印输出中显示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

What am I missing?

我缺少什么?

1 个解决方案

#1


2  

I'm not convinced that you've accurately transcribed the commands you're running. If I have a directory /tmp/src that looks like this:

我不相信你已经准确地转录了你正在运行的命令。如果我有一个目录/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

I can sync it to another server -- and exclude /tmp/src/dir1 -- like this:

我可以将它同步到另一个服务器——排除/tmp/src/dir1——如下所示:

rsync -av --exclude=/dir1 /tmp/src/ server:/tmp/dst/

And the run looks like this:

运行是这样的:

sending incremental file list
created directory /tmp/dst
./
dir2/
dir2/file1
dir2/file2

This appears to exactly match what you've described in your question. I'm using rsync version 3.0.8. I would advise examining both your actual rsync command line and the filesystem closely. If you don't see anything obvious, can you post the actual command you're runing, along with a top level directory listing (unless it's huge)?

这似乎与你在问题中描述的完全吻合。我用的是rsync版本3。0。8。我建议您仔细检查实际的rsync命令行和文件系统。如果您没有看到任何明显的东西,您可以发布您正在运行的实际命令,以及一个*目录列表(除非它很大)吗?

#1


2  

I'm not convinced that you've accurately transcribed the commands you're running. If I have a directory /tmp/src that looks like this:

我不相信你已经准确地转录了你正在运行的命令。如果我有一个目录/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

I can sync it to another server -- and exclude /tmp/src/dir1 -- like this:

我可以将它同步到另一个服务器——排除/tmp/src/dir1——如下所示:

rsync -av --exclude=/dir1 /tmp/src/ server:/tmp/dst/

And the run looks like this:

运行是这样的:

sending incremental file list
created directory /tmp/dst
./
dir2/
dir2/file1
dir2/file2

This appears to exactly match what you've described in your question. I'm using rsync version 3.0.8. I would advise examining both your actual rsync command line and the filesystem closely. If you don't see anything obvious, can you post the actual command you're runing, along with a top level directory listing (unless it's huge)?

这似乎与你在问题中描述的完全吻合。我用的是rsync版本3。0。8。我建议您仔细检查实际的rsync命令行和文件系统。如果您没有看到任何明显的东西,您可以发布您正在运行的实际命令,以及一个*目录列表(除非它很大)吗?