home *** CD-ROM | disk | FTP | other *** search
Wrap
# # 07-MAR-00 I4.0.0.25 APB $$1 Initial submission # ######################################################################### # # Checking migration status # ######################################################################### # Procedure: # CDVersion - gets version of current CD # proc GetCDVersion {} { global PathDlmtr set SourceName "applrev.h" set SourceFile [open [file dirname [info script]]${PathDlmtr}${SourceName}] return [lindex [gets $SourceFile] 2] } ######################################################################### # Procedure: # OracleConnect - check database connection. # # Input parameters: # UserPwd - "username/password" # proc OracleConnect {UserPwd} { global LogMsg StatString ilnk_platform errorCode set PlusOut "" set errorCode "" set FullCmdTxt "WHENEVER OSERROR EXIT 1 exit " catch { exec $ilnk_platform(SqlplusPrg) -s $UserPwd << $FullCmdTxt } PlusOut if {($errorCode != "") && ($errorCode != "NONE")} { set ErrMsg "\nProgramm $ilnk_platform(SqlplusPrg) returned nonzero code:\n $errorCode\n\n" set LogMsg "$ErrMsg\n\n$PlusOut\n\n" set StatString "Status \"CANNOTCONNECT\"\n" error $LogMsg $StatString "STOP" } return $PlusOut } ######################################################################### # Procedure: # ConvertCheck - check if the database is a convert database. # # Input parameters: # UserPwd - "username/password" # proc ConvertCheck {UserPwd} { global LogMsg StatString ilnk_platform errorCode set SqlHead "set head off" set SqlCmd "$SqlHead SELECT count(*) FROM dba_rollback_segs WHERE TABLESPACE_NAME='PTC_HUGERBS_TBSP'; " set seg_num [RunSqlplus ${UserPwd} $SqlCmd] if {$seg_num != 0} { set LogMsg "\nMigration is not supported for Pro/Convert database\n\n" set StatString "Status \"NOTSUPPORTED\"\n" error $LogMsg $StatString "STOP" } } ######################################################################### # Procedure: # RunSqlplus - run SQL*Plus with connection by $UserPwd and executes # all commands in $CmdTxt. # # Input parameters: # UserPwd - "username/password" # CmdTxt - commands to execute # # Returned Value: # Return SQL*Plus output. # proc RunSqlplus {UserPwd CmdTxt} { global LogMsg StatString ilnk_platform errorCode set PlusOut "" set errorCode "" set FullCmdTxt "WHENEVER OSERROR EXIT 1 $CmdTxt exit " catch { exec $ilnk_platform(SqlplusPrg) -s $UserPwd << $FullCmdTxt } PlusOut if {($errorCode != "") && ($errorCode != "NONE")} { set ErrMsg "\nProgramm $ilnk_platform(SqlplusPrg) returned nonzero code:\n $errorCode\n\n" set LogMsg "$ErrMsg\n\n$PlusOut\n\n" set StatString "Status \"SCHEMAERROR\"\n" error $LogMsg $StatString "STOP" } return $PlusOut } ########################################################################## # WriteLog - output string into LogFile file without appending # newline character. You have to specify it explicitly. # # Input parameters: # OutputString - Text for output in log file. # # Return value: # NONE # proc WriteLog {OutputString} { global LogFile if {[file exists ${LogFile}] == 1} { set log_file [open ${LogFile} "a"] } else { set log_file [open ${LogFile} "w"] } puts -nonewline $log_file ${OutputString} flush $log_file close $log_file } ########################################################################## # GetDBCharSet - return current datbase character set. # # Input parameters: # NONE # # Return value: # Text string # proc GetDBCharSet {} { global LogMsg StatString PwdConnectString set SqlCmd {set pagesize 0 set feedback off set Verify off select VALUE from NLS_DATABASE_PARAMETERS where PARAMETER='NLS_CHARACTERSET'; } set charset [RunSqlplus ${PwdConnectString} $SqlCmd] set err_rep [OraErrorReport $charset ""] if {$err_rep != ""} { set ErrMsg "\nError during running sqlplus:" set LogMsg "$ErrMsg\n\n${err_rep}\n$SqlOut\n" set StatString "Status \"SCHEMAERROR\"\n" error $LogMsg $StatString "STOP" } return $charset } ########################################################################## # GetCurrentVersion - return current version string accordingly with # information in DB. # # Input parameters: # NONE # # Return value: # Text string # proc GetCurrentVersion {} { global LogMsg StatString PwdConnectString set SqlHead "set pagesize 0 set feedback off set Verify off " set SqlCmd "$SqlHead col CNT format 9990 select count(*) CNT from PDM.PDM_REVISIONS where REVSTATUS=1; " set str_nmb [RunSqlplus ${PwdConnectString} $SqlCmd] set err_rep [OraErrorReport $str_nmb ""] if {$err_rep != ""} { set ErrMsg "\nError during running sqlplus:" set LogMsg "$ErrMsg\n\n${err_rep}\n$SqlOut\n" set StatString "Status \"SCHEMAERROR\"\n" error $LogMsg $StatString "STOP" } if {[regexp { +1} $str_nmb] != 1} { set ErrMsg "\nError: current version is not defined. Check table PDM_REVISIONS." set LogMsg "$ErrMsg\n" set StatString "Status \"SCHEMAERROR\"\n" error $LogMsg $StatString "STOP" } set SqlCmd "$SqlHead select REVEXE from PDM.PDM_REVISIONS where REVSTATUS=1; " set cur_version [RunSqlplus ${PwdConnectString} $SqlCmd] set err_rep [OraErrorReport $cur_version ""] if {$err_rep != ""} { set ErrMsg "\nError during running sqlplus:" set LogMsg "$ErrMsg\n\n${err_rep}\n$SqlOut\n" set StatString "Status \"SCHEMAERROR\"\n" error $LogMsg $StatString "STOP" } if {$cur_version == ""} { set ErrMsg "\nError: current version is not defined." set LogMsg "$ErrMsg\n" set StatString "Status \"SCHEMAERROR\"\n" error $LogMsg $StatString "STOP" } if {[string first "." $cur_version] == -1} { # # Old style of version numbers # set cur_release "${cur_version}" set cur_version "${cur_release}.1.H-01" } return $cur_version } ########################################################################## # VersionCompare - compare two version of dataserver and return result # # # Input parameters: # VersionLabel1 # VersionLabel2 # # Return value: # -1 - VersionLabel1 is older # 0 - VersionLabel1 and VersionLabel2 are equivalent # 1 - VersionLabel2 is older # 2 - Version isn't supported # proc VersionCompare {VersionLabel1 VersionLabel2} { global LogMsg StatString set ErrMsg "" # General info about labels set SplitLabel1 [split $VersionLabel1 .] set SplitLabel2 [split $VersionLabel2 .] set LengthLabel1 [llength $SplitLabel1] set LengthLabel2 [llength $SplitLabel2] if {($LengthLabel1 != 5) && ($LengthLabel1 != 3)} { set ErrMsg "\nError: Unrecognized version : $VersionLabel1" set LogMsg "$ErrMsg\n" set StatString "Status \"SCHEMAERROR\"\n" error $LogMsg $StatString "STOP" } if {($LengthLabel2 != 5) && ($LengthLabel2 != 3)} { set ErrMsg "\nError: Unrecognized version : $VersionLabel2" set LogMsg "$ErrMsg\n" set StatString "Status \"SCHEMAERROR\"\n" error $LogMsg $StatString "STOP" } if {$LengthLabel1 < $LengthLabel2} { return -1 } if {$LengthLabel1 > $LengthLabel2} { return 1 } set CompareValue 0 if {$LengthLabel1 == 3} { if {[lindex $SplitLabel1 2] != "I-01"} { # not supported return 2 } if {[lindex $SplitLabel2 2] != "I-01"} { # not supported return 2 } if {[string length [lindex $SplitLabel1 0]] < [string length [lindex $SplitLabel2 0]]} { return -1 } if {[string length [lindex $SplitLabel1 0]] > [string length [lindex $SplitLabel2 0]]} { return 1 } if {[lindex $SplitLabel1 0] < [lindex $SplitLabel2 0]} { return -1 } if {[lindex $SplitLabel1 0] > [lindex $SplitLabel2 0]} { return 1 } if {[lindex $SplitLabel1 1] < [lindex $SplitLabel2 1]} { return -1 } if {[lindex $SplitLabel1 1] > [lindex $SplitLabel2 1]} { return 1 } } if {$LengthLabel1 == 5} { for {set i 0} {$i <= 4} {incr i} { if {$i == 0} { if {[string range [lindex $SplitLabel1 0] 1 end] < [string range [lindex $SplitLabel2 0] 1 end]} { set CompareValue -1 break } if {[string range [lindex $SplitLabel1 0] 1 end] > [string range [lindex $SplitLabel2 0] 1 end]} { set CompareValue 1 break } } else { if {[lindex $SplitLabel1 $i] < [lindex $SplitLabel2 $i]} { set CompareValue -1 break } if {[lindex $SplitLabel1 $i] > [lindex $SplitLabel2 $i]} { set CompareValue 1 break } } } } return $CompareValue } ######################################################################### # OraErrorReport - get ORACLE program's output and return list of error # messages and their descriptions. # Return emty string, if ORACLE errors were not found. # # Input parameters: # OraOutput - ORACLE program's output for testing. # NormalErrLst - list of errors, that must be ignored. # # Default Values: # NormalErrLst = "" # proc OraErrorReport {OraOutput {NormalErrLst ""}} { set ErrorsReport "" set OutputStrngs $OraOutput foreach oerr $NormalErrLst { regsub -all $oerr ${OutputStrngs} "It is not error" OutputStrngs } if {[regexp {[A-Z][A-Z]+-[0-9][0-9][0-9][0-9]+:} ${OutputStrngs}] == 0} { return $ErrorsReport } set ErrorsReport " List of error messages:\n\n" set first_item 1 set err_lst "" while {$OutputStrngs != ""} { set eofstr [string first "\n" $OutputStrngs] if {$eofstr == -1} { set msg_str $OutputStrngs set eofstr [string length $OutputStrngs] } else { set msg_str [string range $OutputStrngs 0 [expr {$eofstr-1}]] set eofstr [expr {$eofstr+1}] } if {[regexp {[A-Z][A-Z]+-[0-9][0-9][0-9][0-9]+:} $msg_str err_desc] == 1} { set ErrorsReport "${ErrorsReport}${msg_str}\n" if {$first_item == 1} { set err_lst $err_desc set first_item 0 } else { if {[lsearch -exact $err_lst $err_desc] == -1} { lappend err_lst $err_desc } } } set eoftext [string length $OutputStrngs] set OutputStrngs [string range $OutputStrngs $eofstr $eoftext] } return ${ErrorsReport} } ######################################################################### # Main # set LogMsg "" set StatString "" set SizeString "Size 0\n" catch { #-------------------------------------- # General settings set LogFile [lindex ${argv} 0] switch $tcl_platform(platform) { unix { set PathDlmtr "/" set ORA_HOME $env(ORACLE_HOME) set ilnk_platform(SvrMngr) "$ORA_HOME/bin/svrmgrl" set ilnk_platform(SqlplusPrg) "$ORA_HOME/bin/sqlplus" } windows { set PathDlmtr "\\" set ORA_HOME $env(ORACLE_HOME) if {[file exists "$ORA_HOME/bin/plus33.exe"]} { set ilnk_platform(SvrMngr) "svrmgr23.exe" set ilnk_platform(SqlplusPrg) "plus33.exe" } else { set ilnk_platform(SvrMngr) "svrmgrl.exe" set ilnk_platform(SqlplusPrg) "sqlplus.exe" } } default { set StatString "Status \"NOTSUPPORTED\"\n" set LogMsg "Unsupported tcl_platform(platform)=$tcl_platform(platform)\n" error $LogMsg $StatString "STOP" } } if {![info exists env(ORA_SYS_PWD)]} { set StatString "Status \"NOTSUPPORTED\"\n" set LogMsg "Environment variable ORA_SYS_PWD was not set" error $LogMsg $StatString "STOP" } set PwdConnectString "system/$env(ORA_SYS_PWD)" # Check oracle connection OracleConnect $PwdConnectString # Check if the running database is a Pro/Convert database ConvertCheck $PwdConnectString #******************************************************************************* # Migration/Update behavior evaluation #******************************************************************************* set CurProiVersion [GetCurrentVersion] set CurrentCDVersion [GetCDVersion] if {([VersionCompare $CurProiVersion "I2.0.0.12.3"] >= 0) && ([VersionCompare $CurProiVersion "I4.0.1.19.6"] == -1)} { # # current version between I2.0.0.12.3 (2.0FCS) and I4.0.1.19.6 (3.0FCS) - any 2.x # set StatString "Status \"MIGRATION\"\n" } elseif {([VersionCompare $CurProiVersion "I4.0.1.19.6"] >= 0) && ([VersionCompare $CurProiVersion $CurrentCDVersion] <= 0)} { # # current version between I4.0.1.19.6 (3.0FCS) and current CD version - any 3.x # set StatString "Status \"UPDATE\"\n" } else { # # current version is lower than I2.0.0.12.3 (2.0FCS) # or higher than current CD version # set StatString "Status \"NOTSUPPORTED\"\n" set LogMsg "Current version of dataserver is: $CurProiVersion\n" append LogMsg "Dataserver migration from all versions earlier than I2.0.0.12.3\n" append LogMsg "or later than $CurrentCDVersion using this CD is not supported." error $LogMsg $StatString "STOP" } if {[GetDBCharSet] != "UTF8"} { # # Exceptional situation when migration needed because of DB character set # set StatString "Status \"MIGRATION\"\n" } #******************************************************************************* # The End of Migration/Update Behavior Evaluation #******************************************************************************* #-------------------------------------- # Estimate dmp-file size set ConstSize "1048576" set PackageKo "1.1" set SqlCmd " DROP TABLE pdm_temp_estimate_size; CREATE TABLE pdm_temp_estimate_size ( owner VARCHAR2(30), table_name VARCHAR2(30), tab_size NUMBER ); " set SqlOut [RunSqlplus ${PwdConnectString} $SqlCmd] # ORA-00942: table or view does not exist set err_rep [OraErrorReport $SqlOut "ORA-00942"] if {$err_rep != ""} { set ErrMsg "\nError during running sqlplus:" set LogMsg "$ErrMsg\n\n${err_rep}\n$SqlOut\n" set StatString "Status \"SCHEMAERROR\"\n" error $LogMsg $StatString "STOP" } set SqlCmd "set pagesize 0 set feedback off set verify off set echo off set trim on set space 0 set serveroutput on size 1000000 DECLARE v_i INTEGER; CURSOR table_list1 IS SELECT owner, table_name FROM dba_tables WHERE owner='PDM' AND table_name not IN (SELECT m.table_name FROM dba_tab_columns m WHERE m.owner='PDM' AND m.data_type like '%LONG%'); CURSOR table_list2 IS SELECT distinct t.owner, t.table_name FROM dba_tables t, dba_tab_columns c WHERE t.owner='PDM' AND t.owner=c.owner AND t.table_name=c.table_name AND c.data_type like '%LONG%' ORDER BY t.table_name; CURSOR column_list(tab_name VARCHAR2) IS SELECT column_name FROM dba_tab_columns WHERE owner='PDM' AND table_name=tab_name; BEGIN FOR arg IN table_list1 LOOP dbms_output.put_line('INSERT INTO pdm_temp_estimate_size SELECT '||chr(39)||arg.owner||chr(39)||','||chr(39)||arg.table_name||chr(39)||',sum('); v_i := 0; FOR clm IN column_list(arg.table_name) LOOP IF v_i <= 0 THEN dbms_output.put_line('2+nvl(vsize('||clm.column_name||'),0)+2'); ELSE dbms_output.put_line('+nvl(vsize('||clm.column_name||'),0)+2'); END IF; v_i := v_i + 1; END LOOP; dbms_output.put_line(') total_size FROM '||arg.owner||'.'||arg.table_name||';'); END LOOP; FOR arg IN table_list2 LOOP dbms_output.put_line('ANALYZE TABLE '||arg.owner||'.'||arg.table_name||' COMPUTE STATISTICS;'); dbms_output.put_line('INSERT INTO pdm_temp_estimate_size SELECT '||chr(39)||arg.owner||chr(39)||','||chr(39)||arg.table_name||chr(39)||','); dbms_output.put_line('num_rows*avg_row_len total_size FROM dba_tables WHERE owner='||chr(39)||arg.owner||chr(39)||' AND table_name='||chr(39)||arg.table_name||chr(39)||';'); END LOOP; dbms_output.put_line('COMMIT;'); EXCEPTION WHEN others THEN null; END; / " set SqlOut [RunSqlplus ${PwdConnectString} $SqlCmd] set err_rep [OraErrorReport $SqlOut ""] if {$err_rep != ""} { set ErrMsg "\nError during running sqlplus:" set LogMsg "$ErrMsg\n\n${err_rep}\n$SqlOut\n" set StatString "Status \"SCHEMAERROR\"\n" error $LogMsg $StatString "STOP" } set AddSqlCmd " SELECT ltrim(to_char(sum(com_size),'999999999999999999990')) FROM ( SELECT sum(source_size) * $PackageKo com_size FROM dba_object_size WHERE owner='PDM' AND type IN ('PROCEDURE','FUNCTION','PACKAGE','PACKAGE BODY') UNION SELECT sum(tab_size) FROM pdm_temp_estimate_size UNION SELECT $ConstSize FROM dual); DROP TABLE pdm_temp_estimate_size; " set SqlCmd "set pagesize 0 set feedback off set head off set term on $SqlOut $AddSqlCmd " set SqlOut [RunSqlplus ${PwdConnectString} $SqlCmd] set err_rep [OraErrorReport $SqlOut ""] if {$err_rep != ""} { set ErrMsg "\nError during running sqlplus:" set LogMsg "${ErrMsg}\n\n${err_rep}\n${SqlOut}\n" set StatString "Status \"SCHEMAERROR\"\n" error $LogMsg $StatString "STOP" } set SizeString "Size ${SqlOut}\n" # DO NOT remove dumbVar setting. It will change script behavior!!! set dumbVar "" } MainError if {$errorCode == "STOP" || $errorCode == "" || $errorCode == "NONE"} { WriteLog $StatString WriteLog $SizeString WriteLog $LogMsg exit 0 } WriteLog "Status \"UNKNOWN\"\n" WriteLog "Size 0\n" WriteLog "TCL error code: ${errorCode}\n" WriteLog "TCL error info: ${errorInfo}\n" WriteLog $LogMsg exit 1