Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3a7251d84e | |||
| 6efe39d8ad |
12
ReadMe.md
12
ReadMe.md
@@ -34,11 +34,23 @@ Example file is `stanza.sample.cfg`
|
|||||||
|
|
||||||
This files holds the stanzas to backup
|
This files holds the stanzas to backup
|
||||||
|
|
||||||
|
`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"
|
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
|
```ini
|
||||||
[stanzas]
|
[stanzas]
|
||||||
stanza_a
|
stanza_a
|
||||||
stanza_b:1
|
stanza_b:1
|
||||||
stanza_b:2
|
stanza_b:2
|
||||||
|
stanza_c::/etc/to/config
|
||||||
|
stanza_d:::super user
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -71,6 +71,10 @@ if [ -z "${sudo_user}" ]; then
|
|||||||
echo "sudo_user not set in the config file ${config_file}";
|
echo "sudo_user not set in the config file ${config_file}";
|
||||||
exit;
|
exit;
|
||||||
fi;
|
fi;
|
||||||
|
if [ -z "${pgbackrest_config}" ] ||[ ! -f "${pgbackrest_config}" ]; then
|
||||||
|
echo "Missing pgbackrest default config file ${pgbackrest_config}";
|
||||||
|
exit;
|
||||||
|
fi;
|
||||||
# stanza list file
|
# stanza list file
|
||||||
if [ ! -f "${stanza_file}" ]; then
|
if [ ! -f "${stanza_file}" ]; then
|
||||||
echo "Missing stanza config file ${stanza_file}";
|
echo "Missing stanza config file ${stanza_file}";
|
||||||
@@ -179,6 +183,10 @@ while read -r stanza; do
|
|||||||
# split into the name and repo list
|
# split into the name and repo list
|
||||||
stanza_name=$(echo "${stanza}" | cut -d ":" -f 1);
|
stanza_name=$(echo "${stanza}" | cut -d ":" -f 1);
|
||||||
stanza_repo=$(echo "${stanza}" | awk -F':' '{print (NF>1) ? $2 : ""}');
|
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
|
# override stanza check
|
||||||
if [ -n "${OVERRIDE_STANZA}" ]; then
|
if [ -n "${OVERRIDE_STANZA}" ]; then
|
||||||
# skip if not matching name
|
# skip if not matching name
|
||||||
@@ -187,20 +195,61 @@ while read -r stanza; do
|
|||||||
fi;
|
fi;
|
||||||
# if we have repo set, check if repo is matching
|
# if we have repo set, check if repo is matching
|
||||||
OVERRIDE_STANZA_REPO=$(echo "${OVERRIDE_STANZA}" | awk -F':' '{print (NF>1) ? $2 : ""}');
|
OVERRIDE_STANZA_REPO=$(echo "${OVERRIDE_STANZA}" | awk -F':' '{print (NF>1) ? $2 : ""}');
|
||||||
if [ -n "${OVERRIDE_STANZA_REPO}" ] && [ -n "${stanza_repo}" ] && [ "${stanza_repo}" != "${OVERRIDE_STANZA_REPO}" ]; then
|
if [ -n "${OVERRIDE_STANZA_REPO}" ] && [ "${stanza_repo}" != "${OVERRIDE_STANZA_REPO}" ]; then
|
||||||
continue
|
continue
|
||||||
fi;
|
fi;
|
||||||
# set repo from override
|
# set repo from override
|
||||||
stanza_repo="${OVERRIDE_STANZA_REPO}";
|
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
|
||||||
|
OVERRIDE_STANZA_CONFIG="${stanza_config}";
|
||||||
|
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;
|
fi;
|
||||||
# build the call command
|
# build the call command
|
||||||
CALL=(
|
CALL=(
|
||||||
"sudo" "-u" "${sudo_user}"
|
"sudo" "-u" "${sudo_user}"
|
||||||
"pgbackrest" "--type=${BACKUP_TYPE}" "--stanza=${stanza_name}"
|
"pgbackrest" "--type=${BACKUP_TYPE}" "--stanza=${stanza_name}"
|
||||||
);
|
);
|
||||||
|
_stanza_config="${pgbackrest_config}";
|
||||||
|
if [ -f "${stanza_config}" ]; then
|
||||||
|
_stanza_config="${stanza_config}";
|
||||||
|
fi;
|
||||||
|
stanza_check=$(grep -E "^\[${stanza_name}\]$" "${_stanza_config}");
|
||||||
|
if [ -z "${stanza_check}" ]; then
|
||||||
|
echo "[!] Stanza ${stanza_name} not found in config file ${_stanza_config}, skipping stanza";
|
||||||
|
continue;
|
||||||
|
fi;
|
||||||
if [ -n "${stanza_repo}" ]; then
|
if [ -n "${stanza_repo}" ]; then
|
||||||
|
# check if repo exists in config file with "repo<number>-"
|
||||||
|
repo_check=$(grep -E "^repo${stanza_repo}-" "${_stanza_config}");
|
||||||
|
if [ -z "${repo_check}" ]; then
|
||||||
|
echo "[!] Stanza repo ${stanza_repo} for stanza ${stanza_name} not found in config file ${_stanza_config}, skipping stanza";
|
||||||
|
continue;
|
||||||
|
fi;
|
||||||
CALL=("${CALL[@]}" "--repo=${stanza_repo}");
|
CALL=("${CALL[@]}" "--repo=${stanza_repo}");
|
||||||
fi;
|
fi;
|
||||||
|
if [ -n "${stanza_config}" ]; then
|
||||||
|
if [ ! -f "${stanza_config}" ]; then
|
||||||
|
echo "[!] Stanza config file ${stanza_config} for stanza ${stanza_name} not found, skipping stanza";
|
||||||
|
continue;
|
||||||
|
fi;
|
||||||
|
CALL=("${CALL[@]}" "--config=${stanza_config}");
|
||||||
|
fi;
|
||||||
CALL=("${CALL[@]}" "backup");
|
CALL=("${CALL[@]}" "backup");
|
||||||
# main backup start
|
# main backup start
|
||||||
START=$(date +'%s');
|
START=$(date +'%s');
|
||||||
|
|||||||
@@ -1,2 +1,3 @@
|
|||||||
[PgBackRest]
|
[PgBackRest]
|
||||||
sudo_user=postgres
|
sudo_user=postgres
|
||||||
|
pgbackrest_config=/etc/pgbackrest.conf
|
||||||
|
|||||||
@@ -2,3 +2,5 @@
|
|||||||
stanza_a
|
stanza_a
|
||||||
stanza_b:1
|
stanza_b:1
|
||||||
stanza_b:2
|
stanza_b:2
|
||||||
|
stanca_c::/path/to/config/file
|
||||||
|
stanza_d:::super_user
|
||||||
|
|||||||
Reference in New Issue
Block a user