#!/bin/bash
#
# postgresql data set up program.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# (c) 2003 Copyright TOSHIBA Corporation. All rights reserved.
#
DIR=`pwd`
LOG_FILE="$DIR/test_postgresql_data.log"
DATABASE_DIR="$DIR/database"
PGDATA_FILE="$DIR/pgdata_20031011.tgz"
PGDATA_FILE_SIZE="1351148924"
export LANG=C
if [ -f "$LOG_FILE" ]; then
rm -rf $LOG_FILE
fi
if [ ! -d "$DATABASE_DIR" ]; then
mkdir $DATABASE_DIR
fi
if [ -e "$PGDATA_FILE" ]
then
count=1
cd $DATABASE_DIR
rm -rf pgdata
while true;do
DATE=`date +%Y-%m%d-%H%M-%S:`
echo "$DATE postgresql data setup $count started." \
>> $LOG_FILE
tar xzf $PGDATA_FILE > /dev/null 2>&1
DATE=`date +%Y-%m%d-%H%M-%S:`
if [ ! -d pgdata ]
then
echo "$DATE postgresql data setup failed."
exit 0
fi
SIZE=`ls -lR pgdata | awk '{size+=$5} END {print size}'`
if [ "$SIZE" == "$PGDATA_FILE_SIZE" ]
then
echo "$DATE $count PASS." >> $LOG_FILE
rm -rf pgdata
count=`expr $count + 1`
else
echo "$DATE postgresql data setup error."
exit 0
fi
done
else
echo "Error: $PGDATA_FILE not found."
echo "$0 Test Stop"
fi