I want to exclude folders which are already on a remote server (i.e. test/xyz) and I want to run rsync from my source server where I have test1/xyz folder so I don't want to overwrite xyz folder on remote side.

Also I want to update the files if there any files deleted/added on source server that will be deleted/added on the remote server, but excluding the test/xyz folder.

I have tried below command to exclude the remote directory but it copies excluded directory and files on remote directory.

rsync -ave ssh --exclude=remotedirectory root@IPADDRESS:remotepath --delete sourcepath

Any ideas, please?

2 Answers 2


You have 2 ways.

  1. Just --exclude=dir and there is no difference if it's local or remote, as you anyway do not want to sync it.
  2. Use --rsync-path='rsync --exclude=dir' and remote rsync will be executed with that exclude option.

This should work:

rsync -av --delete --exclude=/xyz/ sourcepath/ root@IPADDRESS:remotepath/

That will exclude "xyz" when it occurs in the root of "sourcepath", and is a directory (the trailing "/" ensures that).

The trailing slashes on the source and destination directories are important. Without that the second rsync run would create a new folder "remotepath/sourcepath", which is probably not what you want.

Also, you had the source and destination parameters the wrong way around, according to you description (but the confusion could be mine).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .