Created
July 26, 2014 18:27
-
-
Save anonymous/a8d42400e5a0b8c60574 to your computer and use it in GitHub Desktop.
Script to ship archive logs from master postgresql to slave server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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