2023-12-03 02:09:46 -05:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
restoreDir=/etc/restore
|
|
|
|
pgsqlDir="$restoreDir/postgresql"
|
|
|
|
|
2023-12-13 02:06:44 -05:00
|
|
|
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
|
2023-12-13 02:06:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2023-12-03 06:44:35 -05:00
|
|
|
hook_before() {
|
2023-12-13 02:06:44 -05:00
|
|
|
if [[ -d "$pgsqlDir" ]]; then
|
|
|
|
rm -rf "$pgsqlDir" || exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
runBackups || exit $?
|
2023-12-03 02:09:46 -05:00
|
|
|
}
|
|
|
|
|
2023-12-03 06:44:35 -05:00
|
|
|
hook_after() {
|
2023-12-13 02:06:44 -05:00
|
|
|
rm -rf "$pgsqlDir" || exit 1
|
2023-12-03 02:09:46 -05:00
|
|
|
}
|
|
|
|
|
2023-12-03 06:44:35 -05:00
|
|
|
hook_fail() {
|
2023-12-13 02:06:44 -05:00
|
|
|
:
|
2023-12-03 06:44:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
hook_final() {
|
2023-12-13 02:06:44 -05:00
|
|
|
:
|
2023-12-03 06:44:35 -05:00
|
|
|
}
|
|
|
|
|
2023-12-03 02:09:46 -05:00
|
|
|
case "$1" in
|
2023-12-13 02:06:44 -05:00
|
|
|
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
|