We don't bite newbies here... much | |
PerlMonks |
Generate rsync filter from list of wanted sub-directoriesby mscharrer (Hermit) |
on Sep 28, 2011 at 15:55 UTC ( [id://928357]=CUFP: print w/replies, xml ) | Need Help?? |
I recently had the need to set up an automated synchronization of a large rsync module (CTAN, yes 'T' not 'P') where I only wanted certain sub-directories to be synchronized. While rsync allows for include/exclude filter the used scheme is a little counter-intuitive. Direct paths like /some/dir/I/want/ don't work because rsync never sees that last dir want if you don't include all parent directories as well. This forces you to include all of them but then exclude all other files and dirs in them, e.g.:
The /*** here means "that directory plus everything in it, including sub-dirs". Older rsync versions needed that as two instructions / and /**. I wrote a Perl script for this which creates a hash-of-hash(-of-hashes)* to hold the directory structure. (Actually Data::Diver would be well suited for this, but I decided to do my own loop because it was simple enough and that package is not part of the current installation on the target server.) Then the hash structure is recursively processed to include all parent directories first and exclude all other things in it afterwards. I added key sorting to get a sorted filter list which is easily proof-read. I added two warnings for the case when a directory should be included fully and partially. In this case it is always included fully. Here the code:
Usage Example
gives:
Back to
Cool Uses for Perl
|
|