I am implementing rdist similar syntax to rsync and I am able sync my files and folders with rsync, but while handling this rdist syntax I am not understanding this part except (/home/user1/log1/*/*/sql.net /home/user1/log1/*/*/core) and my include files of rdist are FILES=(/home/user1/log1 /home/user1/rightlog)

How do I achieve this in rsync? I have tried this rsync -rtu --exclude='/log1/*/*/sql.net' exclude='/log1/*/*/core' $FILES remote@host:$FILES

Am I cloning exact rdist or do I need to tweak more? I am not getting the desired output, and moreover, sometimes sql.net may be present in the other folders, so I cannot do this --exclude=sql.net.


Even without exclude lists, rsync $FILES remote@host:$FILES wouldn't work: it expands to rsync /home/user1/log1 /home/user1/rightlog remote@host:/home/user1/log1 /home/user1/rightlog which would make /home/user1/rightlog the destination (but rsync will complain that you're mixing local and remote sources).

You can specify multiple sources with rsync, but they're all copied to the same destination and parameters such as exclude lists apply to all the sources.

If you need different parameters for different subtrees, then you need to make separate calls to rsync. If you don't need different parameters, then synchronize the common root but include only the parts that you want to synchronize.

rsync --include='/log1' --include='/rightlog' --exclude='/*' /home/user1 remote@host:/home/user1

You don't need separate calls to rsync to have different exclude lists as they just need to include the leading path component.

rsync --include='/log1' --include='/rightlog' --exclude='/*' \
      --exclude='/log1/*/*/sql.net' --exclude='/log1/*/*/core' \
      /home/user1 remote@host:/home/user1
  • great .. but i need to embedd all includes in array variable FILES and everything will go in test.sh which will called by cron.I don't want separate file for include also or all include at command line rsync, should use variable and i will traverse trough for loop i am using SUN os sparc enterprise. – chandu Sep 14 '16 at 6:55
  • @chandu So construct the rsync command line by iterating over the array. – Gilles Sep 14 '16 at 11:55

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.