Skip to content

Instantly share code, notes, and snippets.

@eduardodeoh
Forked from anonymous/ship_logs.sh
Created July 26, 2014 18:27
Show Gist options
  • Select an option

  • Save eduardodeoh/164a38b73bc495a0c159 to your computer and use it in GitHub Desktop.

Select an option

Save eduardodeoh/164a38b73bc495a0c159 to your computer and use it in GitHub Desktop.

Revisions

  1. @invalid-email-address Anonymous created this gist Jul 26, 2014.
    33 changes: 33 additions & 0 deletions ship_logs.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    #!/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