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
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/
.