#!/bin/bash

# Copyright 2005, IBM Corporation

# Do restore for one collaboration area.
# Run the SQL command "select coa_name, coa_id from coa order by coa_id" in your WPC DB Admin to see a list of collab areas and their ids.
#


# Usage of the file
if [[ $# -ne 5 ]]
then
 echo "Usage "
 echo "restore_ghost_items_db2.sh --db=databasename --dbuser=touser --dbpassword=touserpassword --collabid=CollabAreaID --reportfile=ReportFileName"
 echo "Example restore_ghost_items_db2.sh --db=wpcdb --dbuser=wpc1 --dbpassword=wpc1 --collabid=15 --reportfile=myreport"
 
 exit 0
fi

# Declare the variables
DBName=`echo $1 |cut -d "=" -f2`;export DBName
DBUSER=`echo $2 |cut -d "=" -f2`;export DBUSER
DBUserPassword=`echo $3 |cut -d "=" -f2`;export DBUserPassword
CollabID=`echo $4 |cut -d "=" -f2`;export CollabID
ReportFile=`echo $5 |cut -d "=" -f2`;export ReportFile


db2 connect to ${DBName} user ${DBUSER} using ${DBUserPassword}

echo "***********************************************************"
date
echo "Deleting messages from the messages table"
echo "***********************************************************"

db2 "delete from messages"
db2 "commit"

echo "***********************************************************"
echo "Deleting messages is done"
echo "Starting the restore process"
echo "***********************************************************"

db2 "call restore_all(${CollabID})"

db2 "select substr(message_text,1,200) from messages" > ${ReportFile}_after_restore

db2 "terminate"

echo "********************   Restore is done   ***********************"
date
echo "****** Check ${ReportFile}_after_restore file for report *******"
