#!/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:  Archive directory does not exist" 1>&2
  exit 1
fi

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

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

RET="$?"

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

exit 0

