Add some logging.

This commit is contained in:
Andrea Dell'Amico 2021-04-08 16:42:08 +02:00
parent b5a43c3acd
commit 8e390d20f0
1 changed files with 10 additions and 12 deletions

View File

@ -7,7 +7,7 @@ MASTER_HOST=$(hostname -f)
# $1 is {{ psql_data_dir }} while $3 is {{ psql_data_dir }}
#MASTER_DATA="{{ psql_data_dir }}"
MASTER_DATA="${1}"
RECOVERY_TARGET=${2}
RECOVERY_TARGET="${2}"
#RECOVERY_DATA="{{ psql_data_dir }}"
RECOVERY_DATA="${3}"
@ -20,32 +20,30 @@ ssh -T $RECOVERY_TARGET sudo /bin/systemctl stop postgresql
logger "pgpool_recovery_1: stopped postgresql"
# Move the PostgreSQL data directory out of our way.
ssh -T $RECOVERY_TARGET \
"[ -d $RECOVERY_DATA ] && mv $RECOVERY_DATA $RECOVERY_DATA.$TS"
ssh -T "$RECOVERY_TARGET" "[ -d $RECOVERY_DATA ] && mv $RECOVERY_DATA $RECOVERY_DATA.$TS"
logger "pgpool_recovery_1: moved the old data directory on $RECOVERY_TARGET"
# We only use archived WAL logs during recoveries, so delete all
# logs from the last recovery to limit the growth.
rm $MASTER_DATA/archive_log/*
rm "$MASTER_DATA/archive_log/*"
logger "pgpool_recovery_1: removed archive log"
logger "pgpool_recovery_1: removed the archive logs"
# With this file present, our archive_command will actually
# archive WAL files.
touch $MASTER_DATA/archive_log/backup_in_progress
touch "$MASTER_DATA/archive_log/backup_in_progress"
logger "pgpool_recovery_1: touched the backup_in_progress file"
logger "pgpool_recovery_1: ssh -T $RECOVERY_TARGET pg_basebackup -h $MASTER_HOST -p {{ psql_db_port }} -D $RECOVERY_DATA"
# Perform a backup of the database.
ssh -T $RECOVERY_TARGET \
"pg_basebackup -h $MASTER_HOST -p {{ psql_db_port }} -D $RECOVERY_DATA"
ssh -T "$RECOVERY_TARGET" "pg_basebackup -h $MASTER_HOST -p {{ psql_db_port }} -D $RECOVERY_DATA"
logger "pgpool_recovery_1: backup of the database from $MASTER_HOST to $RECOVERY_TARGET"
logger "pgpool_recovery_1: backup of the database from $MASTER_HOST to $RECOVERY_TARGET completed"
# Configure the restore_command to use the archive_log WALs well copy
# Configure the restore_command to use the archive_log WALs we will copy
# over in 2nd_stage.sh.
echo "restore_command = 'cp $RECOVERY_DATA/archive_log/%f %p'" | \
ssh -T $RECOVERY_TARGET "cat > $RECOVERY_DATA/recovery.conf"
echo "restore_command = 'cp $RECOVERY_DATA/archive_log/%f %p'" | ssh -T $RECOVERY_TARGET "cat > $RECOVERY_DATA/recovery.conf"
logger "pgpool_recovery_1: create the restore command on $RECOVERY_TARGET"