Skip to content

Instantly share code, notes, and snippets.

Created July 26, 2014 18:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/a8d42400e5a0b8c60574 to your computer and use it in GitHub Desktop.
Save anonymous/a8d42400e5a0b8c60574 to your computer and use it in GitHub Desktop.
Script to ship archive logs from master postgresql to slave server
#!/bin/sh
#
## This is called to back up the WAL files to the slave.
## This is on top of replication and is used as another
## method to secure data successfully transferring from one
## database server to another.
ARCHIVE_DIR_ON_SLAVE="/var/lib/postgresql/walfiles"
LOG=1
LOG_FILE="/tmp/postgres_wal_archiving.log"
log() { echo "`date --rfc-3339=ns` $1" >> "$LOG_FILE"; }
log_error() { echo "`date --rfc-3339=ns` $1" >> "$LOG_FILE"; exit 1; }
wal_path="$1"
wal_file="$2"
backup_server="db02"
if [ $LOG -eq 1 ]
then
log "Transfering file to backup server, filename: $wal_file"
fi
rsync "$wal_path" "$backup_server:$ARCHIVE_DIR_ON_SLAVE"
if [ $LOG -eq 1 ]
then
if [ "$?" -eq 0 ]; then
log "Transfer to slave server completed"
else
log_error "Sending $wal_file failed."
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment