#!/bin/sh
# Copyright (c) 1997-2009, NeoNova BV, The Netherlands. All rights Reserved.
#
# This software is the copyrighted work of NeoNova BV.
# Use of the software is subject to the general business terms and conditions of NeoNova BV
# and its related transaction documents like license sheets or other written notices.
#
# Any reproduction or redistribution of the software not in accordance with the license terms
# is expressly prohibited by law, and may result in severe civil and criminally penalties.
# Violators will be prosecuted to the maximum extent possible.

#set -x

if [ -f /tmp/export_to_slave-$1.lock ]
then
  exit 0
fi

touch /tmp/export_to_slave-$1.lock

if [ $# -ne 1 ]
then
  echo usage $0 target-hostname
  exit 1
fi

DUMPFILE=/tmp/astium.dump.$$
pg_dump -Fc astium -f $DUMPFILE
scp $DUMPFILE root@$1:$DUMPFILE
ssh root@$1 "/usr/local/astium/sbin/import_into_slave $DUMPFILE < /dev/null >>/var/log/import_into_slave.log 2>&1"
rm -f $DUMPFILE
rm -f /tmp/export_to_slave-$1.lock
