From: Rodrigo Campos Date: Mon, 12 Jul 2010 16:26:10 +0000 (-0300) Subject: Allow config options on a per host basis X-Git-Url: https://git.llucax.com/software/bacap.git/commitdiff_plain/39a46f88097147eafc80c9c9cc8e6a182c3e6a7f Allow config options on a per host basis Signed-off-by: Rodrigo Campos --- diff --git a/README b/README index 878f3dd..c15200c 100644 --- a/README +++ b/README @@ -70,13 +70,19 @@ file. Configuration files are searched in this places: 1. ``/etc/bacaprc`` 2. ``/etc/bacap/bacaprc`` 3. ``bacaprc`` in the same directory as the ``bacap`` script +4. Optional parameter passed as argument to the script +5. ``$CONFIG_PATH/$HOST/bacaprc`` Order is important, since all files are read (if possible) and values in the last configuration file read overwrites old values. The script takes an optional -parameter, which is another location to look for a configuration file. The -configuration file passed as argument will be read last, and an error will be -printed if can't be found (no error is issued if any of the other configuration -files are missing). +parameter, which is another location to look for a configuration file. If the +configuration file passed as argument can't be found, an error will be printed +(no error is issued if any of the other configuration files are missing). +Also, config options could be specified on a per host basis by creating a +``bacaprc`` file in ``$CONFIG_PATH/$HOST``. As a side effect of this, +configuration file(s) are read initially and each time the script backups a new +host. So the configuration file(s) are read at least two times even if you +backup one host. The configuration file is a Bash_ script too, and these are the default values: diff --git a/bacap b/bacap index fb6cc5e..dd83d2e 100755 --- a/bacap +++ b/bacap @@ -38,13 +38,17 @@ RSYNC_RSH="ssh -c arcfour -o Compression=no -x" #_INCLUDE_END_ +SCRIPT_DIR=$(dirname `readlink -f $0`) +BACAPRC=$1 # Load configuration files -source "/etc/bacaprc" 2> /dev/null -source "/etc/bacap/bacaprc" 2> /dev/null -source `dirname \`readlink -f "$0"\``/bacaprc 2> /dev/null -test -n "$1" && source "$1" - +load_config() { + source "/etc/bacaprc" 2> /dev/null + source "/etc/bacap/bacaprc" 2> /dev/null + source "$SCRIPT_DIR/bacaprc" 2> /dev/null + test -n "$BACAPRC" && source "$BACAPRC" +} +load_config export RSYNC_RSH @@ -86,6 +90,9 @@ plog "=========================================================================" ret=0 for host_path in "$CONFIG_PATH"/* do + # Load default config and override config if correspond + load_config + source "$host_path/bacaprc" 2>/dev/null host=`basename "$host_path"` host_backup_path="$BACKUP_PATH/$host" dst="$BACKUP_PATH/$host/$date"