Adding postgresql backup config and script

This commit is contained in:
Eric Renfro 2023-12-13 02:06:44 -05:00
parent 623cb73c5d
commit aa94914ceb
Signed by: psi-jack
GPG key ID: 14977F3A50D9A5BF
2 changed files with 45 additions and 18 deletions

View file

@ -3,36 +3,59 @@
restoreDir=/etc/restore
pgsqlDir="$restoreDir/postgresql"
function readConfig() {
while read -r -a vals
do
[[ "${vals[*]}" =~ ^#.*$ ]] && continue
[[ -z "${vals[0]}" ]] && continue
if [[ "${vals[0]}" -ge 10 ]]; then
echo "${vals[@]}"
fi
done < postgresql.cfg
}
function runBackups() {
local vals
local version
local cluster
while read -r -a vals
do
version="${vals[0]}"
cluster="${vals[1]}"
echo "Backing up PostgreSQL $version - $cluster"
pg_backupcluster "$version" "$cluster" createdirectory || return $?
sudo -u postgres pg_backupcluster "$version" "$cluster" basebackup || return $?
sudo -u postgres pg_backupcluster "$version" "$cluster" dump || return $?
sudo -u postgres pg_backupcluster "$version" "$cluster" expirebasebackups 1 || return $?
sudo -u postgres pg_backupcluster "$version" "$cluster" expiredumps 1 || return $?
done < <(readConfig)
}
hook_before() {
if [[ -d "$pgsqlDir" ]]; then
rm -rf "$pgsqlDir" || exit 1
fi
if [[ -d "$pgsqlDir" ]]; then
rm -rf "$pgsqlDir" || exit 1
fi
state=$(nc 127.0.0.1 5400)
if [[ "$state" != "MASTER" ]]; then
#backupDate=$(date +"%Y-%m-%d")
mkdir -p "$pgsqlDir" || exit 2
/usr/local/sbin/pg_backup -c /etc/postgresql/9.6/main/pg_backup.config
fi
runBackups || exit $?
}
hook_after() {
rm -rf "$pgsqlDir" || exit 1
rm -rf "$pgsqlDir" || exit 1
}
hook_fail() {
:
:
}
hook_final() {
:
:
}
case "$1" in
before) hook_before || exit $?;;
after) hook_after || exit $?;;
fail) hook_fail || exit $?;;
finally) hook_final || exit $?;;
before) hook_before || exit $? ;;
after) hook_after || exit $? ;;
fail) hook_fail || exit $? ;;
finally) hook_final || exit $? ;;
esac

View file

@ -0,0 +1,4 @@
# Configuration for pg_backupcluster stylebackups.
# Format per line: VERSION CLUSTER
# Example: 10 main
10 main