#!/bin/bash
# Populate the specdb databsee for a particular ir

echo "IR = "$1

if [ ! $1 ] 
then
  echo "must specify IR "
  exit
fi

echo " "
echo "Populating the specdb for IR = " $1
echo " "


db2 activate db specdb
db2 deactivate db specdb
db2 drop db specdb
db2set DB2_APM_PERFORMANCE=
db2stop force
db2start
./blddb.sh specdb /specdb | tee /SPECjAppServer2004.logs/blddb.log

# changed by KMR on 2005-04-19
./db2tune.sh
db2stop
db2start
db2 activate db specdb

#db2stop force
#db2 terminate
#db2start
#rerun.sh %1

# ../../bin/setenv.sh # ???-these are wrong        
# ./rebind.sh
../../bin/loaddb.sh $1 | tee  /SPECjAppServer2004.logs/loaddb.log
# ./db2tune.sh
db2stop
db2start

echo "exporting database archive to /archive/archive_${1}..."
if [ -e /archive/archive_$1 ]
then
  echo "removing existing database archive"
  rm -Rf /archive/archive_$1
fi
mkdir /archive/archive_$1
db2 backup database specdb user db2inst1 using ibmdb2 to /archive/archive_$1
# << ibmdb2
# EOF
echo "...done exporting database archive"

# echo "compressing database archive..."
# bzip2 /archive/archive_$1/`ls -1A /archive/archive_$1`
# echo "...done compressing database archive"
