#!/bin/bash

# Archive a Write Ahead Log (WAL) file from the pg_xlog directory.

# Because we don't need the archive on the standby host, we simply
# discard the WAL files there.

# This script is NOT SUPPORTED by Red Hat Global Support Services.

set -eu

WAL_PATH="$1"
WAL_FILENAME="$2"

. /usr/libexec/pgsql-replication.sh

if [ "$HOSTNAME" != "$PRIMARY_HOST" ]; then
    log INFO "Not on $PRIMARY_HOST, exiting"
    exit 0
fi

cp "$WAL_PATH" "$WAL_ARCHIVE_WRITE/$WAL_FILENAME"
