5

I am trying to backup files from cluster to my local computer. On the process, I am trying to avoid some unnecessary sub-directories from cluster being copied.

So I use rsync -av user@cluster.com:/home/dir . --exclude user@cluster.com:/home/dir/subdir, where subdir is the folder I am trying to avoid. However, the above option copies all files and folders including subdir. How to exclude subdir?

SKPS
  • 183
  • 2
  • 15
  • @Arronical: True. The exclude folder must be relative to the source directory and not the absolute path. – SKPS Jul 27 '16 at 10:01
  • It works! I was putting it up as answer. But I would leave this for you.... – SKPS Jul 27 '16 at 10:04
  • Yes. The solution is rsync -av user@cluster.com:/home/dir . --exclude subdir – SKPS Jul 27 '16 at 10:11

1 Answers1

5

The problem is that the path that you hand to --exclude should be relative to the original source path of the rsync command. This also means that you can do away with the / at the beginning of /subdir

Also there's no need to specify the user and host in the --exclude part.

So the correct command would be:

rsync -av user@cluster.com:/home/dir . --exclude subdir

Note that rsync --exclude can also do pattern matching, and the --exclude-from option is a great way to use a file listing multiple exclude patterns if you have more complicated exclusions.

Arronical
  • 19,893