Вы находитесь на странице: 1из 4

SET VERIFY OFF

SET SERVEROUTPUT ON SIZE 1000000


SET PAGESIZE 1000
SET LINESIZE 1000

DEFINE sys_user = ''


column col_temp new_value schema_user
select user col_temp from dual;

CLEAR SCREEN

PROMPT
PROMPT **********************************************************
PROMPT * Currently Logged In User is: &schema_user
PROMPT *
PROMPT * NOTE: You MUST be logged in as the ECM Schema user
PROMPT * If not, press CTRL-C and log in as the ECM Schema User
PROMPT * user and run this script again.
PROMPT *
PROMPT * NOTE: If this user is correct press ENTER to continue.
PROMPT * or press CTRL-C to break now.
PROMPT **********************************************************

PAUSE

CLEAR SCREEN

PROMPT
PROMPT **********************************************************
PROMPT * User Input Required
PROMPT **********************************************************

column COMPUTER format a16


column DESTINATION format a16
column SOURCE format a16
column ID format 99999

select src.computerid "ID", src.name "COMPUTER"


from schregcomps src, schcomputers sc, SCHAGENTS sa, schtasks st
where sc.computerid = src.computerid
and SC.SCHCOMPUTERID = SA.SCHCOMPUTERID
and SA.AGENTID = ST.AGENTID
group by src.computerid, src.name
order by src.computerid;

PROMPT From the list select the id of the computer for to move tasks from
ACCEPT SrcServerID PROMPT 'Server ID: '

select src.computerid "ID", src.name "COMPUTER"


from schregcomps src, schcomputers sc
where src.computerid not in (select computerid from schcomputers)
group by src.computerid, src.name
order by src.computerid;

PROMPT From the list select the id of the computer for to move tasks from
ACCEPT DestServerID PROMPT 'Server ID: '

--##############################################################################
--# Display the user choices for confirmation.
--##############################################################################
CLEAR SCREEN

PROMPT
PROMPT You are moving tasks between the following computers
Select name "SOURCE"
from schregcomps
where computerid = &SrcServerID;

Select name "DESTINATION"


from schregcomps
where computerid = &DestServerID;

PROMPT
PROMPT If this is not correct, you shouldbreak out of this script now.
PROMPT Press the <ENTER> key to continue, or press CTRL-C to break now.
PAUSE

PROMPT ***********************************************************
PROMPT * CURRENT TIMESTAMP INFORMATION
PROMPT ***********************************************************
select current_timestamp from dual;

-- copy scheduler configuration from old server to new server


update schregcomps
set ConfigXML = (select ConfigXML from schregcomps where computerid = &SrcServerID)
where computerid = &DestServerID;
commit;

-- copy network configuration from old server to new server


update schregcomps
set propXML = (select PropXML from schregcomps where computerid = &SrcServerID)
where computerid = &DestServerID;
commit;

-- Set the new computer


update schcomputers set computerid = &DestServerID
where computerid = &SrcServerID;
commit;

--update scheduler delete files


update schdeletefiles set computerid = &DestServerID
where computerid = &SrcServerID;
commit;

--insert a row into the system log showing these schedulers moved.

create table tmpsysloginfo (


SrcID NUMBER,
DestID NUMBER);

insert into tmpsysloginfo (SrcID,DestID) values (&SrcServerID,&DestServerID);


commit;

ALTER SESSION SET time_zone = '0:0';


--PLSQL to do the insert into the current system log table
DECLARE
TYPE a_refcur IS REF CURSOR;
TYPE table_accts IS table of CHAR(38);

accts_table table_accts;
account_cur a_refcur;
nSrcID NUMBER;
nDestID NUMBER;
dActivityDate DATE;
sSrcName VARCHAR2(255);
sDestName VARCHAR2(255);
sGUID CHAR(38);
sCurr_Table CHAR(15);
sUserInfo VARCHAR2(255);
sSchema_User CHAR(50);
sGlobal_name VARCHAR2(4000);
sDesciption VARCHAR2(4000);
sReason VARCHAR2(4000);
nActivityType NUMBER;
sApplication VARCHAR2(50);
sComputer VARCHAR2(50);
sAcctName VARCHAR2(50);
sql_stmt VARCHAR2(1000);
V_ID CHAR(38);
V_DOMAINID CHAR(38);
V_USERINFO VARCHAR2(255);
V_ACTIVITYDATE DATE;
V_DESCRIPTION VARCHAR2(4000);
V_REASON VARCHAR2(4000);
V_ACTIVITYTYPE NUMBER;
V_APPLICATION VARCHAR2(50);
V_COMPUTER VARCHAR2(50);

BEGIN

-- load the computer ids and action date into variables


SELECT srcid, destid INTO nSrcID, nDestID FROM tmpsysloginfo;

-- Get the oracle SID


select global_name into sGlobal_name from global_name;

-- Get the current date / time


Select current_date into dActivityDate from dual;

-- Get the Schema USER


select user into sSchema_User from dual;

-- Create a GUID
select '{'||substr(sys_guid(),1,8)||'-'||substr(sys_guid(),9,4)||'-'||
substr(sys_guid(),13,4)||'-'||substr(sys_guid(),17,4)||'-'||
substr(sys_guid(),20,12)||'}' into sGUID from dual;

-- Get the name of the current system log


SELECT 'SYSTEMLOG' || NUMVALUE INTO sCurr_Table FROM GLOBALCONFIG WHERE
NAME='CURRENT_SYSTEMLOG';

-- Set the user name for the system log.


sUserInfo := 'Oracle Schema User (' || trim(sSchema_User) || '@' ||
sGlobal_name || ')';
-- Get the source computer name
select name into sSrcName from schregcomps where computerid = nSrcID;

-- Get the destination computer name


select name into sDestName from schregcomps where computerid = nDestID;

-- Set the description


sDesciption := 'Moved all tasks and task managers from scheduler computer '
|| sSrcName || ' to scheduler computer ' || sDestName;

-- Set the reason


sReason := 'SQL upgrade generated entry.';

-- Set the activity type


nActivityType := 4;

-- Set the application


sApplication := 'Scheduler';

-- Set the computer


sComputer := '127.0.0.1';

-- Get the list of accounts this computer is used in.


sql_stmt := 'SELECT scfg.domainid FROM SCHCOMPUTERS SC, SCHCFG SCFG WHERE
SCFG.CFGID = SC.CFGID AND SC.COMPUTERID= ' || nDestID;
OPEN account_cur FOR sql_stmt;
FETCH account_cur BULK COLLECT INTO accts_table;
CLOSE account_cur;

FOR indx in accts_table.first..accts_table.last


LOOP
-- Create a GUID
select name into sAcctName from domains where id = accts_table(indx);
select '{'||substr(sys_guid(),1,8)||'-'||substr(sys_guid(),9,4)||'-'||
substr(sys_guid(),13,4)||'-'||substr(sys_guid(),17,4)||'-'||
substr(sys_guid(),20,12)||'}' into sGUID from dual;
sql_stmt := 'insert into '||sCurr_Table||'
(ID,DOMAINID,USERINFO,ACTIVITYDATE,DESCRIPTION,REASON,ACTIVITYTYPE,APPLICATION,COMP
UTER) VALUES
(:V_ID,:V_DOMAINID,:V_USERINFO,:V_ACTIVITYDATE,:V_DESCRIPTION,:V_REASON,:V_ACTIVITY
TYPE,:V_APPLICATION,:V_COMPUTER)';
EXECUTE immediate sql_stmt USING
sGUID,accts_table(indx),sUserInfo,dActivityDate,sDesciption,sReason,nActivityType,s
Application,sComputer;
dbms_output.put_line('Added system log entry for account ' ||
sAcctName);
END LOOP;
COMMIT;

END;
/
ALTER SESSION SET time_zone = dbtimezone;
drop table tmpsysloginfo;

PROMPT ***********************************************************
PROMPT * SCRIPT COMPLETE
PROMPT ***********************************************************

Вам также может понравиться