##################
# About: This file contains step by step instructions
#        for "CoMinder SpaceStat" scripts collection upgrade from previous version  
#        Read carefully all the file before execution of any script.
# 
# Version: 0.55 (2013.06.16)
# Upgrade path: from version 0.54 to 0.55
#

#
# Part 0 - Introduction
#
# * read README.txt, INSTALL.txt and CHANGELOG.txt for product description, general notes,
#   installation and usage instructions. Some usefull information added from previous version.
#
# * If You have testing environment - test installation and usage there first.
#   Upgrade should be safe, but always good practice test, then use.
#
# * In current and next version - incremental non-cummulative upgrade will be supported
#   So upgrade path is:
#   0.52 => 0.53 - see 0.53 version distribution for detailed instructions
#   0.53 => 0.54 - see 0.54 version distribution for detailed instructions
#   0.54 => 0.55 - this file
#

#
# Part I - Upgrade steps
#
#
1.0) setup some environment variables - adjust according to your company/organisation deployment policy!
COMINDER_BASE - base directory for CoMinder products and it's configuration and logs
COMINDER_PROD - root directory for CoMinder products binaries and scripts
                it will have sub-dirs for db, os and other tools
SOFT_HOME - directoiry where SpaceStat will be installed and run 
                 
# for example
COMINDER_BASE=/u01/app/cominder/
COMINDER_PROD=${COMINDER_BASE}/product
SOFT_HOME=${COMINDER_PROD}/db/space_stat
# optional
export COMINDER_BASE COMINDER_PROD SOFT_HOME  

mkdir -p ${COMINDER_PROD}/db
mkdir -p ${COMINDER_BASE}/LOG  # for logs if needed, can create in any place, 
                               # but remember to point output of schedules scripts calls to that dir 


1.1) get archive 
scp ./space_stat.0.55.tar.gz  ${COMINDER_PROD}/db/space_stat.0.55.tar.gz 
cd ${COMINDER_PROD}/db

1.2) backup or rename previous version installation:
mv space_stat space_stat.bak

1.3) unpack tar.gz
# Note! if you are copying already unpacked files from Windows to UNIX/Linux - use ASCII (Text) mode for transfer unpacked files

tar -xzvf space_stat.0.55.tar.gz
space_stat.0.55/
space_stat.0.55/create/
space_stat.0.55/.............

# 
1.4) rename directory 
mv space_stat.0.55 space_stat

# or make symb.link to latest version
# ln -s space_stat.0.55 space_stat
  
# or leave directory with version number if you wish

1.5) Upgrade objects in DB - use instructions from builds/sps_upgrade_054_055.sql
# Note: Next actions in DB should be done by user with DBA role granted.

# can do one by one step or run script as SYSDBA or SPACESTAT db user
# review it anyway before execution
cd space_stat/builds
more sps_upgrade_054_055.sql

export ORACLE_SID=DBSID
sqlplus /nolog 
SQL> 
connect / as sysdba

@sps_upgrade_054_055.sql

   
1.6) Test it is working
# You can do some snaps with DBA user or SPACESTAT user
# DBS - segments (in DB)
# DBF - files (in DB)
set serveroutput on
execute SPACESTAT.SPS_MAKE_SNAP('DBF');
execute SPACESTAT.SPS_MAKE_SNAP('DBS');
#
# or ALL - will make snapshots of all supported types
execute SPACESTAT.SPS_MAKE_SNAP('ALL'); 
#
# change something in db and run the procedure again to have 2nd snapshots with unique ID 
execute SPACESTAT.SPS_MAKE_SNAP('ALL');

# And check data is collected
set lines 400
set pages 100
col DB_NAME format a12
select * from SPACESTAT.SPS_SNAPS;
select count(1) from SPACESTAT.SPS_SNAP_DATA;

quit
# go to root
cd ..

#
# Part II - Setup scripts in OS
#       
Check snapshoting scripts from OS session
2.1) set permissions
ls -l ${SOFT_HOME}/bin/*.* 
chmod o-rwx ${SOFT_HOME}/bin/*.*
chmod u+x ${SOFT_HOME}/bin/*.sh
ls -l ${SOFT_HOME}/bin/*.*
-rwxr-----  1 oracle oinstall 1803 May  8 11:33 /u01/app/cominder/product/db/space_stat/bin/sps_purge.sh
-rw-r-----  1 oracle oinstall 1341 Oct 16  2012 /u01/app/cominder/product/db/space_stat/bin/sps_purge.sql
-rwxr-----  1 oracle oinstall 2090 Apr 12 18:40 /u01/app/cominder/product/db/space_stat/bin/sps_snap.sh
-rw-r-----  1 oracle oinstall  344 Oct 16  2012 /u01/app/cominder/product/db/space_stat/bin/sps_snap.sql

2.2)
# Check snap scripts are working
# If You are on Windows write your own .bat that will call sps_snap.sql, sps_purge.sql
#                       or wait for some next version with Windows support
# If You are on Linux/UNIX - call Shell scripts:  
#
# check snapshoting is working
${SOFT_HOME}/bin/sps_snap.sh DBSID
...
SQL>
PL/SQL procedure successfully completed.
Commit complete.

  COUNT(1)
----------
       406
#

#
# Part III - generate reports
#
3.1) Check reports execution from sql*plus. Reports are in reports directory:
check reports/DIRINFO.txt for details. There are new reports.
All reports are safe - running reports do SELECT ... only
So to find what best suits Your needs just try ALL of them and review output


#
# Part IV - setup old unnecessary snapshots information purging
#
#   If You had done this in 0.54 - skip Part IV - nothing new
4.1) First of all - set retention settings if not done before 
  edit and execute: 
  cfg/cfg_setting.sql
IMPORTANT: take a look inside script to understand settings

#
4.2) Make report of actual or obsolete snapshots with
reports/sps_report_snaps_actual.sql
reports/sps_report_snaps_obsolete.sql

#
4.3) Check purge is working
${SOFT_HOME}/bin/sps_purge.sh DBSID

# If purge was not executed today then  "snaps after purge" reported
# should be less then "snaps before purge" (but really this depends on retention settings)


#
# Part V - update scheduled execution
#

# If all OK with manual snapshoting and purge, schedule regular tasks with DB Scheduler or cron:
# NOTE: In this version scripts moved to bin directory, so adjust path in crontab or other scheduler
#
# Bat-file for Windows is missing, but hope You can write your own and use Task Scheduler
#
# 
5.1) 
# Daily SpaceStat DB segments and files used space statistic collection
15 01 * * * /u01/app/cominder/product/db/space_stat/bin/sps_snap.sh DBSID  1>/u01/app/cominder/LOG/sps_DBSID.snap.log 2>&1
# Purge too old DB segments and files used space statistic
15 02 * * * /u01/app/cominder/product/db/space_stat/bin/sps_purge.sh DBSID 1>/u01/app/cominder/LOG/sps_DBSID.purge.log 2>&1
#

# 
# Part VI - clean
#

If everything OK - clean or arhive the backup
rm -r ${COMINDER_PROD}/db/space_stat.bak
rm -r ${COMINDER_PROD}/db/space_stat.0.55.tar.gz

 
#
# Part VII - Feedback
#
 
#
# Feedback is welcomed in any form to support((at))cominder.eu
#
# To subscribe/unsubscribe to SpaceStat news, just drop e-mail
#  with subject "Subscribe SpaceStat news" (or Unsubscribe)
# Name, Lastname, Company, position and anything more - are optional.
#

#
# Part VIII - UnInstall
#

# Use create/sps_drop.sql script to remove all SPACESTAT content from the database
# except SPACESTAT tablespace
