Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

SOURCE DIRECTORY STRUCTURE:  
/STORAGE/user1/db/Logs/151251/  
/STORAGE/user1/db/Logs/156123/  
/STORAGE/user1/db/Logs/117722/  
/STORAGE/user2/db/Logs/178438/  
/STORAGE/user2/db/Logs/161265/  

PREFERRED DESTINATION DIRECTORY STRUCTURE  
/LOGS/user1/151251/  
/LOGS/user1/156123/  
/LOGS/user1/117722/  
/LOGS/user2/178438/  
/LOGS/user2/161265

The command I've tried is:

rsync -azvr user@server.com:/STORAGE/*/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
add comment

1 Answer 1

up vote 1 down vote accepted

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

rsync -asvr --include '*/' --include 'Logs/***' --exclude '*' user@server.com:/STORAGE/ /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 '*' user@server.com:/STORAGE/ /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
show 4 more comments

Your Answer

 
discard

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.