I want to copy /opt/intranet and all its subdirectories and files but i need to exclude /opt/intranet/helpdesk and all of its children. Do I start from the server I want to copy, or do I run the command from the destination server and ssh the command to the source?

rsync -avr -e ssh root@ --exclude=/opt/intranet/helpdesk . failed as it was syncing the helpdesk folder.

  • Shouldn't it be --exclude=root@ Just guessing. – Jacajack Jan 4 '17 at 17:03
  • No, it still syncs it. – Jon Weinraub Jan 4 '17 at 17:12
  • 1
    Yeah, I've just tried it. It turns out that --exclude paths have to be relative to the source path. In your case it probably should look like this --exclude=helpdesk. Take a look here: serverfault.com/questions/396117/… – Jacajack Jan 4 '17 at 17:15
  • 1
    Yeah that did the trick, the --exclude=helpdesk without the IP address a second time. Thanks. – Jon Weinraub Jan 4 '17 at 17:23

You have to specify, into the --exclude option, a:

Path relative to the source path of the rsync command

In your case:

rsync -avr -e ssh root@ . --exclude=helpdesk

In general case:

rsync -avr -e ssh root@$HOSTNAME:/<source_folder> . --exclude=<relative folder>  

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.