Compare commits
2 Commits
v1.1.0
...
developmen
| Author | SHA1 | Date | |
|---|---|---|---|
| 0b3d47b5d4 | |||
| 3a7251d84e |
20
ReadMe.md
20
ReadMe.md
@@ -21,11 +21,13 @@ Two files must be created
|
||||
|
||||
Example file is `pgbackrest.sample.cfg`
|
||||
|
||||
This file holds the sudo_user for calling the commands
|
||||
This file holds the sudo_user for calling the commands and the main pgbackrest config file.
|
||||
If the super user or config file does not exists an error will be shown
|
||||
|
||||
```ini
|
||||
[PgBackRest]
|
||||
sudo_user=postgres
|
||||
pgbackrest_config=/etc/pgbackrest.conf
|
||||
```
|
||||
|
||||
### `config/stanza.cfg`
|
||||
@@ -34,16 +36,30 @@ 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::/config`
|
||||
|
||||
The script checks for the following things during each run
|
||||
|
||||
- stanza name exists in the main config file, or in the override config file if set
|
||||
- check if repo number exist in main config file, or in the override config file if set
|
||||
- override config file exists
|
||||
- override super does not exist
|
||||
|
||||
```ini
|
||||
[stanzas]
|
||||
stanza_a
|
||||
stanza_b:1
|
||||
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}";
|
||||
exit;
|
||||
fi;
|
||||
if ! id "${sudo_user}" &>/dev/null; then
|
||||
echo "Sudo user ${sudo_user} does not exist, skipping stanza";
|
||||
exit
|
||||
fi;
|
||||
if [ -z "${pgbackrest_config}" ] ||[ ! -f "${pgbackrest_config}" ]; then
|
||||
echo "Missing pgbackrest default config file ${pgbackrest_config}";
|
||||
exit;
|
||||
@@ -185,6 +189,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 +204,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 +212,21 @@ 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
|
||||
if ! id "${stanza_super_user}" &>/dev/null; then
|
||||
echo "[!] Sudo user ${stanza_super_user} for stanza ${stanza_name} does not exist, skipping stanza";
|
||||
continue;
|
||||
fi;
|
||||
sudo_user="${stanza_super_user}";
|
||||
fi;
|
||||
# build the call command
|
||||
CALL=(
|
||||
|
||||
@@ -3,3 +3,4 @@ stanza_a
|
||||
stanza_b:1
|
||||
stanza_b:2
|
||||
stanca_c::/path/to/config/file
|
||||
stanza_d:::super_user
|
||||
|
||||
Reference in New Issue
Block a user