大网数据广告活动
服务器运维问答

Rsync using absolute paths

· 52CE 我爱测

I have two RHEL 7 servers. On my Source I have the following directories /sourcestuff/testresync /sourcestuff/testresync/incl1 /sourcestuff/testresync/incl1/test1.txt /sourcestuff/testresync/incl2 /sourcestuff/testresync/incl2/te…

问题原文

原帖链接 · Mark Sookram · CC BY-SA 4.0

I have two RHEL 7 servers.

On my Source I have the following directories

/sourcestuff/testresync
/sourcestuff/testresync/incl1
/sourcestuff/testresync/incl1/test1.txt
/sourcestuff/testresync/incl2
/sourcestuff/testresync/incl2/test2.txt
/sourcestuff/testresync/excl3
/sourcestuff/testresync/excl3/test2.txt
/sourcestuff/testresync/excl4
/sourcestuff/testresync/excl4/test2.txt

On my Destination I have the following directories

/destinationstuff/testresync
/destinationstuff/testresync/incl1
/destinationstuff/testresync/incl2
/destinationstuff/testresync/excl3
/destinationstuff/testresync/excl4

What I am trying to do is copy the data from my Source to my Destination and exclude the /sourcestuff/testresync/excl3 and /sourcestuff/testresync/excl4 from the Source

What I have tried

rsync -av --relative /sourcestuff/testrsync/./ --exclude '/sourcestuff/testrsync/excl3/' --exclude '/sourcestuff/testrsync/excl4/' user@SERVERIP:/destinationstuff/testrsync

I have read the documentation that the -exclude option relies on the source but everything I try the excl3 and excl4 data still gets transferred.

I have also tried the other way does not work

What I want my Destination to look like:

/destinationstuff/testresync
/destinationstuff/testresync/incl1
/destinationstuff/testresync/incl1/test1.txt  
/destinationstuff/testresync/incl2
/destinationstuff/testresync/incl2/test2.txt
/destinationstuff/testresync/excl3
/destinationstuff/testresync/excl4

已采纳解答

原帖链接 · meuh · CC BY-SA 4.0

As you know, when you use --relative then normally a source path like /a/b/ will get reproduced at a destination of /d as /d/a/b/, and to exclude directory /a/b you would use --exclude /a/b/.

However, when you add the /./ to the source path, like /a/./b/ then only the part after the dot is copied, i.e. you get /d/b/. But, the exclude path has to change too, to be only the part after the dot, --exclude /b/.

So modify your exclude patterns to something like /excl3/.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2020-05-07)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。