I have simple script that backing up data from remote server via ssh using rsync.I have external config file for that.In this config file I have variables: OPTIONS, REMOTE_IP, SOURCE and DESTINATION.Now I need to add more remote servers and start using single script for multiple servers.I want define it with sections (like [SERVER_01],[SERVER_02]...) in config.Script:# You can provide external configuration file if you specify it with -c option# Then if you haven't specified it, use one from ~/rsync_script/config.cfgif [[ $1 == -c ]]; then    CONFIG_FILE=$2else    CONFIG_FILE=~/rsync_script/config.cfgfi# Add constants from config file to script's environmentif [[ -f $CONFIG_FILE ]]; then    . $CONFIG_FILEfi# Create full path before running rsync, because rsync cannot mkdir with -p option# Run rsync with parameters from config.cfg and put files to $DESTINATION/$REMOTE_IP/YYYY-MM-DDif [[ -d $DESTINATION ]]; then    mkdir -p $DESTINATION$REMOTE_IP/$(date +%A)    rsync -avx \        --timeout=30 \        $OPTIONS \        rsync@$REMOTE_IP:$SOURCE $DESTINATION$REMOTE_IP/$(date +%F)else        echo failurefiConfig:# Set extra options for rsync commandOPTIONS=--itemize-changes --log-file=changes.log# Set IP address of server the you want to backupREMOTE_IP=192.168.11.123# Set the folder on remote server to backupSOURCE=/home/rsync/somedata# Set the destination folder on local machineDESTINATION=/backup/Suggest me a best way to solve this, pleaseAny code comments and advices are welcomed :)Thanks
Rsync backup script for multiple servers
bash;shell;shell script;scripting;rsync
Here's a possible scenario. Put your existing rsync code (if [[ -d $DESTINATION ...)into a shell function, say runbackup, and replace the part that does . $CONFIG_FILE by a loop that reads the fileand looks for the [SERVER_...] section separator. When it finds one, it calls therunbackup function (except for the first one). For the other lines it does eval on each line just like . does.To ensure runbackup is called on the last section, a dummy [END] section is added to the input.(cat $CONFIG_FILE; echo '[END]') |while read linedo if [[ $line =~ ^\[([A-Z_0-9]+)\] ]]   then if [ -n $OPTIONS -a -n $REMOTE_IP ]        then echo section $section             runbackup        fi        section=${BASH_REMATCH[1]} # captured from =~ regex above        unset OPTIONS REMOTE_IP SOURCE DESTINATION   else eval $line   fidone 