Deleting all the old versions that are created before a given date in all the catalogs OR a specific catalog
******************************************************************************


Description: 

Using delete_versions_by_date.sh script you can purge all the old versions/rows that are created before a given date. For item data, old versions are deleted from all the catalogs. 

You can use delete_versions_by_ctg_date.sh to purge all the old versions that are created before a given date in a specific catalog. This is for item data only.

You can use estimate_versions_by_date.sh and estimate_versions_by_ctg_date.sh to get an estimate on how many rows will get deleted by the delete scripts.

Execution Environment:

Shell script that invokes DB2 CLI and SQL in bash shell

Usage for estimate_versions_by_date.sh:

estimate_versions_by_date.sh --cmpid=<CompanyID> --date=YYYY-MM-DD --dbuser=<dbuser> --dbpassword=<password> --dbname=<dbname>

Usage for estimate_versions_by_ctg_date.sh:

estimate_versions_by_ctg_date.sh --cmpid=<CompanyID> --ctgid=<CatalogId> --date=YYYY-MM-DD --dbuser=<dbuser> --dbpassword=<password> --dbname=<dbname>

Usage for delete_versions_by_date.sh:
 
delete_versions_by_date.sh --cmpid=<CompanyID> --date=YYYY-MM-DD --dbuser=<dbuser> --dbpassword=<password> --dbname=<dbname>

Usage for delete_versions_by_ctg_date.sh:

delete_versions_by_ctg_date.sh --cmpid=<CompanyID> --ctgid=<CatalogId> --date=YYYY-MM-DD --dbuser=<dbuser> --dbpassword=<password> --dbname=<dbname>

Options:
 
cmpid: Company ID. You can get this from CMP table using simple sql "select * from cmp".

date: To select old versions that are created before given date. Date must be in format YYYY-MM-DD

dbuser: Name of the database user. This is value of db_userName parameter in $TOP/etc/default/common.properties file.

dbpassword: Password of the database user. This is value of db_password parameter in $TOP/etc/default/common.properties file.

dbname: Name of the database. This can be found in db_url parameter value in $TOP/etc/default/common.properties file.

ctgid: Catalog or Container ID. You can get this from CTG table using simple sql "select * from ctg"


Example: 

./delete_versions_by_date.sh --cmpid=40001 --date=2005-09-30 --dbuser=wpc1 --dbpassword=wpc1 --dbname=wpcdb | tee delete_old_versions.out

./delete_versions_by_date.sh --cmpid=40001 --ctgid=804 --date=2005-09-30 --dbuser=wpc1 --dbpassword=wpc1 --dbname=wpcdb | tee delete_old_versions.out

WARNING:
1. It is strongly recommended to take a physical or logical backup of the database before running the script
2. Don't run the delete script, if you find the estimated number of db rows/items to be deleted is more the 1 Million. Please contact WPC support. 

Procedure:

1. Stop the WPC application on which you are going to run this script. 
   Make sure that there are no jobs running when you stop the application.
   Stop the application on all the nodes if it is clustered environment.
2. Run delete_versions_by_date.sh or delete_versions_by_ctg_date.sh script from $TOP/src/maintenance/ directory
3. After the script is run, it is recommended to run DB2 REORG TABLE and INDEX
4. Re-start the WPC application.


Notes:

Amount of time taken to finish running the script depends on the size of catalogs and the number of old versions in One or all catalogs according to respective script. 

These scripts will not delete the rows that belong to latest version of any catalog.

Logs for the scripts are written to $TOP/logs/default/ starting with del_version.

