resticprofiles-base/scripts/postgresql

62 lines
1.4 KiB
Text
Raw Normal View History

2023-12-03 02:09:46 -05:00
#!/bin/bash
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
2023-12-13 02:19:41 -05:00
done < /etc/resticprofile/config/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
runBackups || exit $?
2023-12-03 02:09:46 -05:00
}
hook_after() {
rm -rf "$pgsqlDir" || exit 1
2023-12-03 02:09:46 -05:00
}
hook_fail() {
:
}
hook_final() {
:
}
2023-12-03 02:09:46 -05:00
case "$1" in
before) hook_before || exit $? ;;
after) hook_after || exit $? ;;
fail) hook_fail || exit $? ;;
finally) hook_final || exit $? ;;
2023-12-03 02:09:46 -05:00
esac