creation of backupninja.conf.d to customize backupninja.conf parameters

Introduction of a conf.d directory to safely override parameters from the backupninja.conf.

Change-Id: Ie17c4b9891f6eb31cb19a62ca09f0839aea7967e
Signed-Off-By: Emil Breiner <emil.breiner@krumedia.com>
This commit is contained in:
Emil Breiner 2021-03-23 16:51:55 +01:00
parent 5cc80402dd
commit 18d17bba97
3 changed files with 37 additions and 3 deletions

View File

@ -75,6 +75,9 @@ usecolors = yes
# default value for 'when'
when = everyday at 01:00
# conf.d for backupninja.conf overrides
config_d_directory = @CFGDIR@/backupninja.conf.d
# programs paths
# SLAPCAT=/usr/sbin/slapcat
# LDAPSEARCH=/usr/bin/ldapsearch

View File

@ -58,20 +58,46 @@ function version_ge() {
function setfile() {
CURRENT_CONF_FILE=$1
# initialize empty and ommit a default value
CURRENT_CONF_D_DIR=""
getconf config_d_directory
# for consistency the config key is in lowercase
CURRENT_CONF_D_DIR=$config_d_directory
}
function setsection() {
CURRENT_SECTION=$1
}
#
# sets a global var with name equal to $1
# to the value of the configuration parameter $1
# $2 is the default.
#
# Begin by parsing the conf.d directory for configs.
# If the param is not found there fallback on the packaged backupninja.conf.
# if the param is still not found fallback to the default.
function getconf() {
ret=""
CURRENT_PARAM=$1
ret=`@AWK@ -f $libdirectory/parseini S=$CURRENT_SECTION P=$CURRENT_PARAM $CURRENT_CONF_FILE`
# check if conf.d directory exists
if [ -d "$CURRENT_CONF_D_DIR" ]; then
CURRENT_CONF_D_FILES=$CURRENT_CONF_D_DIR/*.conf
# iterate over all *.conf files in conf.d dir
for CURRENT_CONF_D_FILE in $CURRENT_CONF_D_FILES; do
# retrieve param from file
ret=`@AWK@ -f $libdirectory/parseini S=$CURRENT_SECTION P=$CURRENT_PARAM $CURRENT_CONF_D_FILE`
# exit the iteration if the param is set
if [ -n "$ret" ]; then
break
fi
done
fi
# after exiting the loop caused by a not set param parse the packaged backupninja.conf
if [ "$ret" == "" ]; then
ret=$(@AWK@ -f $libdirectory/parseini S=$CURRENT_SECTION P=$CURRENT_PARAM $CURRENT_CONF_FILE)
fi
# if nothing is returned, set the default
if [ "$ret" == "" -a "$2" != "" ]; then
ret="$2"

View File

@ -124,6 +124,11 @@ These values for 'when' are invalid:
when = tuesday at 2
when = tues at 02
.TP
.B config_d_directory
Directory for configuration overrides. Files dropped in this directory have
to end with .conf. Misspelled parameter break the parsing of this directory.
.TP
.SH DEFAULTS