b036602676
- Improve error handling of recovery script. Feature safe: yes
40 lines
871 B
Bash
40 lines
871 B
Bash
#!/bin/sh
|
|
#
|
|
# $FreeBSD$
|
|
#
|
|
# In postgresql.conf:
|
|
# archive_command = 'test -f /proj/pgsql/data/archive_log/%f || cp %p /proj/pgsql/data/archive_log/%f'
|
|
#
|
|
|
|
SRC=pgsql@$(hostname)
|
|
SRCDIR=$1
|
|
DEST=pgsql@$2
|
|
DESTDIR=$3
|
|
ARCLOG=$1/archive_log
|
|
|
|
logger="logger -t pgpool -p local0.info"
|
|
rsync="/usr/local/bin/rsync -av --delete --checksum"
|
|
excl="--exclude=pg_log --exclude=postmaster.pid"
|
|
psql="/usr/local/bin/psql"
|
|
|
|
/bin/sh <<EOF | ${logger} 2>&1
|
|
|
|
$psql -c "select pg_start_backup('pgpool-recovery')" template1
|
|
|
|
ssh $DEST "
|
|
/usr/local/bin/pg_ctl -D $DESTDIR -s -m fast stop;
|
|
rm -f $DESTDIR/backup_label"
|
|
|
|
echo "restore_command = 'scp $SRC:$ARCLOG/%f %p'" > $SRCDIR/recovery.conf
|
|
|
|
$rsync $SRCDIR/ $excl $DEST:/$DESTDIR/
|
|
|
|
ssh $DEST "
|
|
mkdir -p $DESTDIR/pg_xlog/archive_status;
|
|
mkdir -p $DESTDIR/pg_log"
|
|
|
|
rm -f $SRCDIR/recovery.conf
|
|
|
|
$psql -c 'select pg_stop_backup()' template1
|
|
|
|
EOF
|