******************************************************************************************
Scripts to Report,Cleanup and Restore Ghost Items in DB2 Database of WPC

Authors: 	Dennis Arnon, Abhinav Shekhar and Sreenivasa Paidi
Last Modified: 	10-JUN-2008
******************************************************************************************

This scripts can be used to detect and cleanup ghost items in WPC running on DB2 databases.

This directory consists of following SQL scripts:

create_backup_tables_db2.sql
create_procedures_db2.sql
create_views_db2.sql
drop_backup_tables_db2.sql
drop_procedures_db2.sql
drop_views_db2.sql

This directory consists of following Shell Scripts:

workflow_integrity_verify.sh
workflow_integrity_restore.sh
report_ghost_items_db2.sh
clean_ghost_items_db2.sh
restore_ghost_items_db2.sh


SQL scripts are used to create/drop backup tables, views and procedures that are used in the shell scripts.
Shell scripts are used to report, cleanup and restore ghost items in the WPC database.

Grant execute permission on all shell scripts by running 'chmod +x *.sh' command, if not present already.

Note: You need to know values of db_url, db_userName, db_password parameters of $TOP/etc/default/common.properties file before running this script. 
      Ask the WPC application administrator in your company for a copy of common.properties file from the WPC application server.

      It is very important to make sure that you can connect to the database using command line interface (CLI) before running the scripts.
      You can use a simple "db2 connect to" command given below to see if you can connect to the database.
      
      db2 connect to <dbname> user <dbusername> using <dbpassword>
      

WORKFLOW_INTEGRITY_VERIFY.SH
-------------------
workflow_integrity_verify.sh generates ghost item reports for all collab areas in the schema, one at a time.
It will create one report file for each collab id under the directory called ghost_items_reports under current working directory.
Name of report file looks like report_MON_DD_YYYY_HHMISS_COAID.txt
For example report_Oct_12_2005_105241_17.txt

Syntax:
workflow_integrity_verify.sh --db=<databasename> --dbuser=<dbusername> --dbpassword=<dbuserpassword>

Example:
workflow_integrity_verify.sh --db=wpcdb --dbuser=wpc1 --dbpassword=wpc1 | tee report.log


WORKFLOW_INTEGRITY_RESTORE.SH
---------------------

workflow_integrity_restore.sh will cleanup ghost items in all the collab areas in a schema, one at a time.

It will create three report files for each collab id under the directory called ghost_items_reports under current working directory.
Names of report files look like report_MON_DD_YYYY_HHMISS_COAID_before_cleanup.txt, report_MON_DD_YYYY_HHMISS_COAID_cleanup.txt, and report_MON_DD_YYYY_HHMISS_COAID_after_cleanup.txt
For example report_Oct_12_2005_105241_17_before_cleanup.txt,  report_Oct_12_2005_105241_17_cleanup.txt, and  report_Oct_12_2005_105241_17_after_cleanup.txt

Syntax:
workflow_integrity_restore.sh --db=<databasename> --dbuser=<dbusername> --dbpassword=<dbuserpassword>

Example:
workflow_integrity_restore.sh --db=wpcdb --dbuser=wpc1 --dbpassword=wpc1 | tee clean.log

Important Note: Take a full backup of the database before trying workflow_integrity_restore on the database schema.

Note: You do not have to run workflow_integrity_verify.sh before workflow_integrity_restore.sh because cleanup automatically runs the report for each collab id before running cleanup. 
      This report is store in file report_MON_DD_YYYY_HHMISS_COAID_before_cleanup.tx
            
Reporting Ghost Items in a Single Collaboration Area: 
-----------------------------------------------------

report_ghost_items_db2.sh script is used to report ghost items information in a given collaboration area.

Syntax:

report_ghost_items_db2.sh --db=<dbname> --dbuser=<dbusername> --dbpassword=<password> --collabid=<collabareaID> --reportfile=<ReportFileName>


Where

dbname is name of the database. This can be found in db_url parameter of common.properties file. For example wpcdb is dbname in jdbc:db2:wpcdb

dbusername is the name of database user.This is value of db_userName parameter in common.properties file.

password is password of database user. This is value of db_password parameter in common.propertis file.

collabareaID is the coa_id from coa table.
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

ReportFileName is a user defined log file name in which you want to store the final report.


Example:

report_ghost_items_db2.sh --db=wpcdb --dbuser=wpc1 --dbpassword=wpc1 --collabid=3 --reportfile=myreport


Cleaning Up Ghost Items in a Single Collaboration Area:
---------------------------------------------------------

clean_ghost_items_db2.sh script is used to cleanup ghost items in a given collaboration area.

Syntax: 

clean_ghost_items_db2.sh --db=<dbname> --dbuser=<dbusername> --dbpassword=<password> --collabid=<collabareaID> --reportfile=<ReportFileName>


Where

dbname is name of the database. This can be found in db_url parameter of common.properties file. For example wpcdb is dbname in jdbc:db2:wpcdb

dbusername is the name of database user.This is value of db_userName parameter in common.properties file.

password is password of database user. This is value of db_password parameter in common.propertis file.

collabareaID is the coa_id from coa table.
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

ReportFileName is a user defined log file name in which you want to store the final report.

Example:

clean_ghost_items_db2.sh --db=wpcdb --dbuser=wpc1 --dbpassword=wpc1 --collabid=3 --reportfile=myreport

Important Note: Take a full backup of the database before trying cleanup on the database schema.

Restoring Ghost Items in a Single Collaboration Area:
--------------------------------------------------------
restore_ghost_items_db2.sh can be used to restore given collaboration area related database rows from backup tables.

For a given state of backup tables, this proceudure can be run multiple times with the same effect as running it once.
(doing so is neither necessary nor recommended of course).

Syntax: 

restore_ghost_items_db2.sh --db=<dbname> --dbuser=<dbusername> --dbpassword=<password> --collabid=<collabareaID> --reportfile=<ReportFileName>


Where

dbname is name of the database. This can be found in db_url parameter of common.properties file. For example wpcdb is dbname in jdbc:db2:wpcdb

dbusername is the name of database user.This is value of db_userName parameter in common.properties file.

password is password of database user. This is value of db_password parameter in common.propertis file.

collabareaID is the coa_id from coa table.
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

ReportFileName is a user defined log file name in which you want to store the final report.


Example:

restore_ghost_items_db2.sh --db=wpcdb --dbuser=wpc1 --dbpassword=wpc1 --collabid=3 --reportfile=myreport
 

Note: 

If you want to empty backup tables after restoring rows for a collaboration area, run drop_backup_tables_db2.sql and create_backup_tables_db2.sql
Don't empty the backup tables before restoring the rows.

Example:

(In the following example wpcdb is the dbname and wpc1 is the db user name and password):

db2 connect to wpcdb user wpc1 using wpc1
db2 -tf drop_backup_tables_db2.sql
db2 -tf create_backup_tables_db2.sql


 
 






