Adding postgresql backup config and script
This commit is contained in:
parent
623cb73c5d
commit
aa94914ceb
2 changed files with 45 additions and 18 deletions
|
@ -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
|
||||
|
|
4
templates/config/postgresql.cfg
Normal file
4
templates/config/postgresql.cfg
Normal file
|
@ -0,0 +1,4 @@
|
|||
# Configuration for pg_backupcluster stylebackups.
|
||||
# Format per line: VERSION CLUSTER
|
||||
# Example: 10 main
|
||||
10 main
|
Loading…
Reference in a new issue