Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to accomplish the below with RSYNC but can't quite figure out the syntax. My source contains a folder for each user, then some subfolders under Logs. I need to capture everything under the numeric folder with the sync.



The command I've tried is:

rsync -azvr*/db/Logs/*/ /LOGS/

This succeeds in copying all the files from all the numeric subfolders but I need to create the directory structure above (/LOGS/user/uniqueid/individual files).

Is there a way to accomplish this?

share|improve this question
up vote 1 down vote accepted

You can use rsync filters to specify which subpaths you want transferred:

rsync -asvr --include '*/' --include 'Logs/***' --exclude '*' /LOGS/

This will create all the source directories on the destination (but not containing any files). To not do this you need to explicitly include all parent directories:

rsync -asvr --include '/STORAGE/' --include '/STORAGE/*/' --include '/STORAGE/*/db/' --include '/STORAGE/*/db/Logs/***' --exclude '*' /LOGS/

Edit: To exclude files with a certain extension, add an --exclude pattern at the front:

rsync -asvr --exclude '*.bdb' --include ...
share|improve this answer
Thank you! But will this create the directory structure on the destination server? – Jason Feb 20 '13 at 17:09
@Jason Yup.​​​​ – mgorven Feb 20 '13 at 17:11
Thanks! I just tried that and there are no files found for sync...? I also tried --include '*/db/Logs/***' and that didn't seem to do the trick either? – Jason Feb 20 '13 at 17:17
@Jason Ah, the parent directories need to be explicitly included. See my edit for two options. – mgorven Feb 20 '13 at 17:20
I really appreciate your help! I'm a bit closer but still not quite there. The command is now syncing the files but it's transferring the source directory structure. So on the destination end, I'm ending up with /LOGS/user1/db/Logs/151251, etc. Any way I can have it transfer to the destination so that it eliminates the db and Logs folders and puts the numeric folders directly under the user folder (/LOGS/user1/151251, etc.)? Thanks again!! – Jason Feb 20 '13 at 17:36

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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