I have the configuration file like this in sections
rsync -avz --exclude-from 'content from config file rsync exclude' source/ destination/
--exclude-from you will have to isolate the relevant section of the config into a temporary file. This is easy to do with a bit of sed:
tmp_file=$(mktemp) sed -n '1,/rsync_exclude/d;/\[/,$d;/^$/d;p' config.file > $tmp_file rsync -avz --exclude-from $tmp_file source/ destination/
I am omitting error checking and cleanup for clarity.
Note that rsync can read the exclude pattern from the stdin for an
- input, so this is even shorter:
sed -n '1,/rsync_exclude/d;/\[/,$d;/^$/d;p' config.file | \ rsync -avz --exclude-from - source/ destination/
1,/rsync_exclude/dexcludes all lines up to the rsync_exclude section entry
/\[/,$dexcludes everything from the start of the next section to the end of the file
/^$/dexcludes empty lines (this is optional)
All of the above extracts the relevant section from the config.