From 3a7251d84ef342609fb38aea1d2388a0fbd460a6 Mon Sep 17 00:00:00 2001 From: Clemens Schwaighofer Date: Tue, 2 Dec 2025 14:55:36 +0900 Subject: [PATCH] Allow setting super user in stanza config --- ReadMe.md | 9 ++++++++- bin/pgbackrest_backup.sh | 14 ++++++++++++++ config/stanza.sample.cfg | 1 + 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/ReadMe.md b/ReadMe.md index 270d6a0..d57e37b 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -34,16 +34,23 @@ Example file is `stanza.sample.cfg` This files holds the stanzas to backup -`stanza:repo number:path to config file` +`stanza:repo number:path to config file:super user` If the stanza has several repo settings as in "repo1-...", "repo2-..." then the repo to target can be listed in here by ":repo number" The third optional parameter is a config file path +The forth optional parameter is the super user to use + +If parameters are not used but laters are, the empties need to be set with just the ":" + +`stanza::/conifg` + ```ini [stanzas] stanza_a stanza_b:1 stanza_b:2 stanza_c::/etc/to/config +stanza_d:::super user ``` diff --git a/bin/pgbackrest_backup.sh b/bin/pgbackrest_backup.sh index 76fc966..2216c7c 100755 --- a/bin/pgbackrest_backup.sh +++ b/bin/pgbackrest_backup.sh @@ -185,6 +185,8 @@ while read -r stanza; do stanza_repo=$(echo "${stanza}" | awk -F':' '{print (NF>1) ? $2 : ""}'); # if we have a config stanza_config=$(echo "${stanza}" | awk -F':' '{print (NF>1) ? $3 : ""}'); + # for possible override super user + stanza_super_user=$(echo "${stanza}" | awk -F':' '{print (NF>3) ? $4 : ""}'); # override stanza check if [ -n "${OVERRIDE_STANZA}" ]; then # skip if not matching name @@ -198,6 +200,7 @@ while read -r stanza; do fi; # set repo from override stanza_repo="${OVERRIDE_STANZA_REPO}"; + # config OVERRIDE_STANZA_CONFIG=$(echo "${OVERRIDE_STANZA}" | awk -F':' '{print (NF>2) ? $3 : ""}'); # if we have a config set in the stanza config, but none in the override, use the one from the stanza config if [ -z "${OVERRIDE_STANZA_CONFIG}" ] && [ -n "${stanza_config}" ]; then @@ -205,6 +208,17 @@ while read -r stanza; do else stanza_config="${OVERRIDE_STANZA_CONFIG}"; fi; + # super user + OVERRIDE_STANZA_SUPER_USER=$(echo "${OVERRIDE_STANZA}" | awk -F':' '{print (NF>3) ? $4 : ""}'); + if [ -z "${OVERRIDE_STANZA_SUPER_USER}" ] && [ -n "${stanza_super_user}" ]; then + OVERRIDE_STANZA_SUPER_USER="${stanza_super_user}"; + else + stanza_super_user="${OVERRIDE_STANZA_SUPER_USER}"; + fi; + fi; + # set override sudo user + if [ -n "${stanza_super_user}" ]; then + sudo_user="${stanza_super_user}"; fi; # build the call command CALL=( diff --git a/config/stanza.sample.cfg b/config/stanza.sample.cfg index 573fdad..264c4a4 100644 --- a/config/stanza.sample.cfg +++ b/config/stanza.sample.cfg @@ -3,3 +3,4 @@ stanza_a stanza_b:1 stanza_b:2 stanca_c::/path/to/config/file +stanza_d:::super_user