#!/bin/sh

# archive_command script for Standalone Hot Backup

# SET THIS VARIABLE TO YOUR ARCHIVE DIRECTORY
ARCHIVE="/mnt/pg_archive"

FULLPATH="$1"
FILE="$2"

if [ ! -d "$ARCHIVE" ] ; then
  echo "$0:  ERROR:  Archive directory does not exist" 1>&2
  exit 1
fi

if [ -f "$ARCHIVE/$FILE" ] ; then
  echo "$0:  ERROR:  Archive file $FILE already exists in archive directory" 1>&2
  exit 1
fi

cp "$FULLPATH" "$ARCHIVE/$FILE"

RET="$?"

if [ "$RET" -ne 0 ] ; then
  echo "$0:  ERROR:  Archive copy of $FILE failed with return code $RET" 1>&2
fi

exit $RET

