Update PgBackRest wrapper script and move the config data into separate folder
This commit is contained in:
2
.shellcheckrc
Normal file
2
.shellcheckrc
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
shell=bash
|
||||||
|
external-sources=true
|
||||||
32
ReadMe.md
32
ReadMe.md
@@ -2,16 +2,40 @@
|
|||||||
|
|
||||||
Wrapper to call the full/differential backup on all stanzas
|
Wrapper to call the full/differential backup on all stanzas
|
||||||
|
|
||||||
> [!notice]
|
|
||||||
> Currently all stanzas are hardoded, this should change
|
|
||||||
|
|
||||||
## Options
|
## Options
|
||||||
|
|
||||||
```txt
|
```txt
|
||||||
-b (backuptype): full/diff
|
-b (backuptype): full/diff
|
||||||
-s (stanza): override stanza name, must be in list
|
-s (stanza): override stanza name, must be in stanza.cfg file
|
||||||
-l list available stanza
|
-l list available stanza
|
||||||
-t test run
|
-t test run
|
||||||
```
|
```
|
||||||
|
|
||||||
Either `-l` or `-b` option must be set
|
Either `-l` or `-b` option must be set
|
||||||
|
|
||||||
|
## Config
|
||||||
|
|
||||||
|
Two files must be created
|
||||||
|
|
||||||
|
### `config/pgbackrest.cfg`
|
||||||
|
|
||||||
|
Example file is `pgbackrest.sample.cfg`
|
||||||
|
|
||||||
|
This file holds the sudo_user for calling the commands
|
||||||
|
|
||||||
|
```ini
|
||||||
|
[PgBackRest]
|
||||||
|
sudo_user=pgbackrest
|
||||||
|
```
|
||||||
|
|
||||||
|
### `config/stanza.cfg`
|
||||||
|
|
||||||
|
Example file is `stanza.sample.cfg`
|
||||||
|
|
||||||
|
This files holds the stanzas to backup
|
||||||
|
|
||||||
|
```ini
|
||||||
|
[stanzas]
|
||||||
|
stanza_a
|
||||||
|
stanza_b
|
||||||
|
```
|
||||||
|
|||||||
@@ -49,36 +49,54 @@ function convert_time
|
|||||||
|
|
||||||
## VARIABLES
|
## VARIABLES
|
||||||
|
|
||||||
|
REGEX_COMMENT="^[\ \t]*#";
|
||||||
|
INI_BLOCK="^\[[A-Za-z]*\]";
|
||||||
|
BASE_FOLDER=$(dirname "$(readlink -f "$0")")"/";
|
||||||
|
CONFIG="${BASE_FOLDER}../config/";
|
||||||
BACKUP_TYPE="";
|
BACKUP_TYPE="";
|
||||||
OVERRIDE_STANZA="";
|
OVERRIDE_STANZA="";
|
||||||
LIST_STANZA=0;
|
LIST_STANZA=0;
|
||||||
TEST=0;
|
TEST=0;
|
||||||
sudo_user="pgbackrest";
|
config_file="${CONFIG}pgbackrest.cfg";
|
||||||
# testweb (replaces kome) (aws2/ohio)
|
stanza_file="${CONFIG}stanza.cfg";
|
||||||
# zac fte (aws2/tokyo)
|
if [ -f "${config_file}" ]; then
|
||||||
# sushi database
|
# shellcheck disable=SC1090
|
||||||
# udon core
|
# shellcheck disable=SC2283
|
||||||
# mailing-service-a (aws2/oregon)
|
source <(grep = "${config_file}" | sed 's/ *= */=/g')
|
||||||
# url-redirect-logging (aws9/tokyo)
|
else
|
||||||
# mrktsec (aws3/tokyo)
|
echo "Missing config file ${config_file}";
|
||||||
# instawin (aws8/tokyo)
|
exit;
|
||||||
stanza_list="testwebegplusww zacfte sushidatabase udoncore mailingservicea urlredirectlogging mrktsec instawin";
|
fi;
|
||||||
|
if [ -z "${sudo_user}" ]; then
|
||||||
|
echo "sudo_user not set in the config file ${config_file}";
|
||||||
|
exit;
|
||||||
|
fi;
|
||||||
|
# stanza list file
|
||||||
|
if [ ! -f "${stanza_file}" ]; then
|
||||||
|
echo "Missing stanza config file ${stanza_file}";
|
||||||
|
exit;
|
||||||
|
fi;
|
||||||
|
|
||||||
PRINTF_BLOCK="=== [%-8s: %19s] ==[%s]===============>\n";
|
PRINTF_BLOCK="=== [%-8s: %19s] ==[%s]===============>\n";
|
||||||
|
|
||||||
## OPT PARSEIN
|
## OPT PARSEIN
|
||||||
|
|
||||||
while getopts ":b:s:lt" opt; do
|
while getopts ":b:s:lt" opt; do
|
||||||
case "${opt}" in
|
case "${opt}" in
|
||||||
b) # backuptype
|
b)
|
||||||
|
# backuptype
|
||||||
BACKUP_TYPE="${OPTARG}";
|
BACKUP_TYPE="${OPTARG}";
|
||||||
;;
|
;;
|
||||||
s) # stanza
|
s)
|
||||||
|
# stanza
|
||||||
OVERRIDE_STANZA="${OPTARG}";
|
OVERRIDE_STANZA="${OPTARG}";
|
||||||
;;
|
;;
|
||||||
l) # list
|
l)
|
||||||
|
# list
|
||||||
LIST_STANZA=1;
|
LIST_STANZA=1;
|
||||||
;;
|
;;
|
||||||
t) # test
|
t)
|
||||||
|
# test
|
||||||
TEST=1;
|
TEST=1;
|
||||||
;;
|
;;
|
||||||
:)
|
:)
|
||||||
@@ -106,6 +124,23 @@ if [ $LIST_STANZA -eq 1 ]; then
|
|||||||
for stanza in ${stanza_list}; do
|
for stanza in ${stanza_list}; do
|
||||||
echo "${stanza}";
|
echo "${stanza}";
|
||||||
done;
|
done;
|
||||||
|
while read -r stanza; do
|
||||||
|
# skip empty
|
||||||
|
[ -z "${stanza}" ] && continue;
|
||||||
|
# skip starting with #
|
||||||
|
[[ "${stanza}" =~ ${REGEX_COMMENT} ]] && continue;
|
||||||
|
# skip the ini header blocks
|
||||||
|
[[ "${stanza}" =~ ${INI_BLOCK} ]] && continue;
|
||||||
|
# if override stanza matching
|
||||||
|
if [ "${stanza}" = "${OVERRIDE_STANZA}" ]; then
|
||||||
|
echo "[*] ${stanza}";
|
||||||
|
else
|
||||||
|
echo "[ ] ${stanza}";
|
||||||
|
fi;
|
||||||
|
done <<< "$(cat "${stanza_file}")";
|
||||||
|
echo "";
|
||||||
|
echo "Entry marked with '*' is set as override stanza, and will be the only one backed up";
|
||||||
|
echo "";
|
||||||
exit;
|
exit;
|
||||||
fi;
|
fi;
|
||||||
|
|
||||||
@@ -124,20 +159,40 @@ SET_OVERRIDE_STANZA=0;
|
|||||||
# if we have override single host
|
# if we have override single host
|
||||||
if [ -n "${OVERRIDE_STANZA}" ]; then
|
if [ -n "${OVERRIDE_STANZA}" ]; then
|
||||||
echo "+ Set override stanza too: ${OVERRIDE_STANZA}";
|
echo "+ Set override stanza too: ${OVERRIDE_STANZA}";
|
||||||
for stanza in ${stanza_list}; do
|
while read -r stanza; do
|
||||||
|
# skip empty
|
||||||
|
[ -z "${stanza}" ] && continue;
|
||||||
|
# skip starting with #
|
||||||
|
[[ "${stanza}" =~ ${REGEX_COMMENT} ]] && continue;
|
||||||
|
# skip the ini header blocks
|
||||||
|
[[ "${stanza}" =~ ${INI_BLOCK} ]] && continue;
|
||||||
|
# if override stanza matching
|
||||||
if [ "${stanza}" = "${OVERRIDE_STANZA}" ]; then
|
if [ "${stanza}" = "${OVERRIDE_STANZA}" ]; then
|
||||||
stanza_list="${OVERRIDE_STANZA}";
|
stanza_list="${OVERRIDE_STANZA}";
|
||||||
SET_OVERRIDE_STANZA=1;
|
SET_OVERRIDE_STANZA=1;
|
||||||
break;
|
break;
|
||||||
fi;
|
fi;
|
||||||
done;
|
done <<< "$(cat "${stanza_file}")";
|
||||||
if [ $SET_OVERRIDE_STANZA = 0 ]; then
|
if [ $SET_OVERRIDE_STANZA = 0 ]; then
|
||||||
echo "[!!!] Failed to set override stanza: ${OVERRIDE_STANZA}";
|
echo "[!!!] Failed to set override stanza: ${OVERRIDE_STANZA}";
|
||||||
exit;
|
exit;
|
||||||
fi;
|
fi;
|
||||||
fi;
|
fi;
|
||||||
# run backup
|
# run backup
|
||||||
for stanza in ${stanza_list}; do
|
while read -r stanza; do
|
||||||
|
# skip empty
|
||||||
|
[ -z "${stanza}" ] && continue;
|
||||||
|
# skip starting with #
|
||||||
|
[[ "${stanza}" =~ ${REGEX_COMMENT} ]] && continue;
|
||||||
|
# skip the ini header blocks
|
||||||
|
[[ "${stanza}" =~ ${INI_BLOCK} ]] && continue;
|
||||||
|
# override stanza check
|
||||||
|
if [ -n "${OVERRIDE_STANZA}" ]; then
|
||||||
|
if [ "${stanza}" != "${OVERRIDE_STANZA}" ]; then
|
||||||
|
continue
|
||||||
|
fi;
|
||||||
|
fi;
|
||||||
|
# main backup start
|
||||||
START=$(date +'%s');
|
START=$(date +'%s');
|
||||||
# shellcheck disable=SC2059
|
# shellcheck disable=SC2059
|
||||||
printf "${PRINTF_BLOCK}" "START" "$(date +'%F %T')" "${stanza}";
|
printf "${PRINTF_BLOCK}" "START" "$(date +'%F %T')" "${stanza}";
|
||||||
@@ -145,12 +200,12 @@ for stanza in ${stanza_list}; do
|
|||||||
if [ $TEST -eq 1 ]; then
|
if [ $TEST -eq 1 ]; then
|
||||||
echo "sudo -u ${sudo_user} pgbackrest --type=${BACKUP_TYPE} --stanza=${stanza} backup;";
|
echo "sudo -u ${sudo_user} pgbackrest --type=${BACKUP_TYPE} --stanza=${stanza} backup;";
|
||||||
else
|
else
|
||||||
sudo -u ${sudo_user} pgbackrest --type="${BACKUP_TYPE}" --stanza="${stanza}" backup;
|
sudo -u "${sudo_user}" pgbackrest --type="${BACKUP_TYPE}" --stanza="${stanza}" backup;
|
||||||
fi;
|
fi;
|
||||||
DURATION=$(( $(date +'%s')-START ));
|
DURATION=$(( $(date +'%s')-START ));
|
||||||
# shellcheck disable=SC2059
|
# shellcheck disable=SC2059
|
||||||
printf "${PRINTF_BLOCK}" "END" "$(convert_time ${DURATION})" "${stanza}";
|
printf "${PRINTF_BLOCK}" "END" "$(convert_time ${DURATION})" "${stanza}";
|
||||||
done;
|
done <<< "$(cat "${stanza_file}")";
|
||||||
echo "* PgBackrest Backup end";
|
echo "* PgBackrest Backup end";
|
||||||
if [ $TEST -eq 1 ]; then
|
if [ $TEST -eq 1 ]; then
|
||||||
echo "[..........] TEST RUN ONLY";
|
echo "[..........] TEST RUN ONLY";
|
||||||
|
|||||||
3
config/.gitignore
vendored
Normal file
3
config/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
pgbackrest.cfg
|
||||||
|
stanza.cfg
|
||||||
|
!.gitignore
|
||||||
2
config/pgbackrest.sample.cfg
Normal file
2
config/pgbackrest.sample.cfg
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
[PgBackRest]
|
||||||
|
sudo_user=pgbackrest
|
||||||
3
config/stanza.sample.cfg
Normal file
3
config/stanza.sample.cfg
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
[stanzas]
|
||||||
|
stanza_a
|
||||||
|
stanza_b
|
||||||
Reference in New Issue
Block a user