home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 8 Other
/
08-Other.zip
/
db22fr.zip
/
SQLUEX01.EX5
< prev
next >
Wrap
Text File
|
1992-11-06
|
46KB
|
1,056 lines
/*************************************************************************/
/*************************************************************************/
/* SQLUEXIT */
/* */
/* 566933603 COPYRIGHT IBM CORP. 1987, 1991 */
/* LICENSED MATERIAL - PROGRAM PROPERTY OF IBM */
/* Refer to Copyright Instructions Form Number G120-3083 */
/* */
/* This command file is provided as an sample of how to handle */
/* exit requests from the IBM Database Manager to perform various */
/* requests. It may be modified to meet your particular needs. */
/* */
/* For further information, see the IBM OS/2 Guide to Database */
/* Manager. */
/* */
/*************************************************************************/
signal on halt /* call HALT: routine on CTRL-BREAK */
'@ECHO OFF'
/******************************************************************************/
/* PROLOGUE */
/******************************************************************************/
/******************************************************************************/
/* */
/* SAMPLE NAME : SQLUEX01.CMD */
/* */
/* PURPOSE : This is a example using IBM Corporation's PMTAPE 2.0 */
/* software to manage files for Database Manager's Backup and */
/* Restore utilities and to Archive and Retrieve Database Manager */
/* log files. */
/* */
/* This sample User Exit was developed using PMTAPE */
/* software Version 2.0. */
/* */
/* NOTE: This file must be renamed SQLUEXIT.CMD and located in */
/* PATH before it can be invoked by the Database Manager. */
/* */
/* NOTE: Uncomment the "OPTIONS" line following this prologue */
/* for DBCS environments. */
/* */
/* OPTIONS: (1) This sample provides a detailed audit trail of every */
/* call ( stored in a separate file for each function) */
/* including timestamp and parameters received (can */
/* optionally be disabled ). */
/* */
/************* (2) See the INIT procedure for details on configuration ********/
/* options. IT IS ASSUMED THAT THE DATABASE MANAGER AND */
/* PMTAPE ARE INSTALLED ON C DRIVE. If not you can go to */
/* Default Configuration Values in INIT procedure and */
/* change it as required. The databases can be created */
/* on any drive. */
/* */
/* */
/* Backup/Restore Notes: */
/* */
/* (1) The user must use this userexit program to backup */
/* the database and to restore the database. If the */
/* database is not backed up using this userexit program */
/* then the restore function will fail. */
/* */
/* */
/* (2) Each backup of a database requires two Backup Sets on the */
/* tape media. One for the special dbname.UIF file and one */
/* for the actual database files. */
/* */
/* */
/* (3) It is possible to backup more than one version of the same */
/* database. If so you need to change the DATABASE.TPF file */
/* for the RESTPROC so that it contains the name of the backup */
/* set you want to restore */
/* */
/* */
/* (4) You can customize the DATABASE.TPF to run backup and */
/* restore to your desired specification. */
/* */
/* */
/* (5) If Archive and retrive options are to be used then user */
/* MUST set the User Exit and Log Retain options ON in */
/* configuration tool in the Database Manager. */
/* */
/* Archiving Notes: */
/* */
/* This example allows for "staging" of log files prior to */
/* calling PMTAPE. Modify the "LOGS_TO_HOLD" configuration */
/* parameter in INIT procedure to contain the number of logs to be */
/* staged prior to calling PMTAPE. It should be noted that the */
/* LOGS_TO_HOLD parameter is on a Database Manager level, */
/* however, the individual logs are staged in subdirectories */
/* by database. */
/* */
/* */
/* */
/* Retrieve Notes: */
/* */
/* To retrieve a database the user can call database rollforward */
/* */
/* */
/* OUTPUTS : (1) Activity to the screen */
/* (2) Optional activity to an audit file ("option".LOG) */
/* (3) Error file ("option".ERR) on error conditions */
/* (4) Staged log files */
/* */
/* */
/* USAGE : */
/* */
/* DATABASE MANAGER CALLS SQLUEXIT */
/* SQLUEXIT OPTION PARM1 PARM2 PARM3 PARM4 ╒PARM5■ */
/* */
/* where : OPTION = 'ARCHIVE' ( save a log file ) */
/* 'RETRIEVE' ( get a log file ) */
/* 'BACKUP' ( backup database files ) */
/* 'RESTORE' ( restore database files ) */
/* */
/******************************************************************************/
/****************************************************************************/
/* OPTIONS "ETMODE" "EXMODE" */ /* Uncomment for DBCS environment */
/* TRACE ?R */ /* Uncomment to trace batch file */
/************************/
/* Get input parameters */
/************************/
parse upper arg OPT PARM1 PARM2 PARM3 PARM4 PARM5
PARMS = ' PARAMETERS ==> ' /* Log the parameters received */
PARMS = PARMS ||OPT' 'PARM1' 'PARM2,
' 'PARM3' 'PARM4' 'PARM5
/***************************************************************************/
/*************************** INITIALIZE VARIABLES *****************************/
/***************************************************************************/
DB_DRIVE = strip(PARM1) /* ex. C: */
call INIT /* Initialize User defined variables and configuration parms */
/****************************************************************************/
/***************************** SQLUEXIT MAIN BEGIN ***************************/
/****************************************************************************/
/***********************************************/
/* Register this call to the SQLUEXIT log file */
/***********************************************/
if AUDIT = 'Y' then /* Audit trail enabled? */
do
if stream(UEXIT_LOG, 'c', 'query exists') = '' then /* No log file */
do
cfg_line = 'Initial Configuration: ', /* Make current configuration */
'Audit <'AUDIT'> ', /* the first line in the file */
'Number of log files to stage <'LOGS_TO_HOLD'>'
call lineout UEXIT_LOG, cfg_line
end
call lineout UEXIT_LOG, ' '
call lineout UEXIT_LOG, DT /* Write timestamp to the log file */
call lineout UEXIT_LOG, ' '
call lineout UEXIT_LOG, PARMS /* Write parameters to log file */
call lineout UEXIT_LOG, ' '
end
/*******************************************/
/* Jump to the function requested by caller */
/*******************************************/
select
when OPT = 'ARCHIVE' then signal ARCHPROC /* Archive logs */
when OPT = 'RETRIEVE' then signal RETVPROC /* Retrieve logs */
when OPT = 'BACKUP' then signal BUPROC /* Backup database */
when OPT = 'RESTORE' then signal RESTPROC /* Restore database */
OTHERWISE do /* Unknown option */
ELINE = 'The option "'OPT'" is not valid.'
sqluexitrc = IBM_RC.PARM
signal FINISH
end
end
/****************************** END SQLUEXIT MAIN ***************************/
/***************************************************************************/
/******************************* BACKUP DATABASE ***************************/
/***************************************************************************/
/* */
/* BACKUP sample of Database Manager call to the user exit: */
/* */
/* SQLUEXIT BACKUP C: BRNSDDB1 C:\SQLDBDIR\SQL00001.BKP BRNSDDB1-684686581 1 */
/* */
/* Requests SQLUEXIT to backup the database files listed in the */
/* response file C:\SQLDBDIR\SQL00001.BKP for database BRNSDDB1 */
/* which is located on drive C:. The mode is '1' which indicates */
/* this is the first (of two) calls required to complete the */
/* backup process. Label BRNSDDB1-684686581 (database-timestamp) is */
/* provided to SQLUEXIT to assist in backup management by SQLUEXIT */
/* if desired. */
/* */
/****************************************************************************/
BUPROC:
call checkparms /* Check that the input parameters are valid */
/*********************************************/
/* Clear surrounding spaces from input parms */
/*********************************************/
DB_DRIVE = strip(PARM1) /* ex. C */
DB_NAME = strip(PARM2) /* ex. BRNSDDB1 */
RESP_FILE = strip(PARM3) /* ex. C:\SQLDBDIR\SQL00001.BKP */
LABEL = strip(PARM4) /* ex. BRNSDDB1-684686581 */
MODE = strip(PARM5) /* ex. 1 */
/*****************************************************/
/* To create a .tpf file from PARM3 which will be used by */
/* PMTAPE to backup the database. */
/*****************************************************/
tpffile=PMT_DIR'\pmtape\database.tpf'
'ERASE 'tpffile' 1>NUL 2>NUL'
/* If the file being erased doesn't exist then no error is reported */
rsplst = PARM3
call LINEOUT tpffile,"!BACKUP",1
/******************/
/* The backup set name is given the same name as the database name */
/* so that when restore makes a call to restore the database the backup */
/* set name will be the same as the database name */
/*******************/
call LINEOUT tpffile,'/w scnf /l 'PMT_DIR'\PMTAPE\BACKLOG xi /m /n "'DB_NAME'" /r /c 0 /g '
numlin = LINES(rsplst) /* LINES( ) will return 0 end of file is reached */
DO WHILE (numlin >= 1)
inline = LINEIN(rsplst)
call LINEOUT tpffile,"/b /b rhs /q /S" inline
numlin = LINES(rsplst)
END
call LINEOUT tpffile /* close the file */
/***********************************************************/
/****************************************************/
/* Make call to PMTAPE to backup file(s) */
/****************************************************/
ifile = PMT_DIR"\PMTAPE\BACKLOG"
'ERASE 'ifile
'PMTAPE 'PMT_DIR'\PMTAPE\DATABASE.TPF'
/************************/
call verify_backup
call checkrc /* Check return code */
/********************************************************/
/* ERASING INDEX FILE */
/*********************************************************/
/* The index file contains information about the backup set name */
/* for all the files on PMTAPE. Every time a certain database is */
/* backed up the lines containing the info about that database */
/* are deleted. */
/*************************************************************/
indxfile = DBM_DIR'\PMTINDEX.DAT'
if LINES(indxfile) = 1 then
do
tempfile = DBM_DIR'\TEMPOUT.DAT'
DO WHILE (LINES(indxfile)=1)
string=LINEIN(indxfile)
lastline = string
tempname=SUBSTR(string,21)
slash_loc=POS('\',tempname)
dbname=LEFT(tempname,slash_loc-1)
if dbname<>DB_NAME then
call lineout tempfile, string
end /* do */
call LINEOUT tempfile,lastline
call lineout indxfile
call lineout tempfile
'ERASE 'indxfile
indxfile = DBM_DIR'\PMTINDEX.DAT'
'COPY 'tempfile' 'indxfile
'ERASE 'tempfile
end
/***************************************************************************/
signal FINISH /* Finish up */
/***************************** END BACKUP DATABASE *************************/
/****************************************************************************/
RESTPROC:
tpffile=PMT_DIR'\PMTAPE\DATABASE.tpf'
/* If the file being erased does not exist then no error is reported */
'ERASE 'tpffile' 1>NUL 2>NUL'
call checkparms /* Check that the input parameters are valid */
/*********************************************/
/* Clear surrounding spaces from input parms */
/*********************************************/
DB_DRIVE = strip(PARM1) /* ex. C: */
DB_NAME = strip(PARM2) /* ex. BRNSDDB1 */
RESP_FILE = strip(PARM3) /* ex. C:\SQLDBDIR\SQL00001.BKP */
REST_DIR = strip(PARM4) /* ex. BRNSDDB1-684686581 */
MODE = strip(PARM5) /* ex. 1 */
/************************************************************/
/* To create a .tpf file from PARM3 which will be used by */
/* PMTAPE to backup the database. */
/************************************************************/
rsplst = PARM3
call LINEOUT tpffile,"!Restore",1
call LINEOUT tpffile,"/w socnf /m /t "DB_DRIVE""REST_DIR" /p 2 /k 0 /o 2"
call LINEOUT tpffile,"/b /b rhs /q"
if MODE = 1 then
call LINEOUT tpffile,'/s' '"'DB_NAME"\*"'"'
else
call LINEOUT tpffile,'/s' '"'DB_NAME"-2\*"'"'
call LINEOUT tpffile
/***************************************************/
/* Make call to PMTAPE to backup file(s) */
/****************************************************/
if MODE = 1 then
'PMTAPE 'PMT_DIR'\PMTAPE\DATABASE.TPF'
else 'PMTAPE 'PMT_DIR'\PMTAPE\DATABASE.TPF'
call checkrc /* Check return code */
signal FINISH /* Finish up */
/***************************** END RESTORE DATABASE ************************/
/****************************************************************************/
/***************************** ARCHIVE A LOG FILE *****************************/
/****************************************************************************/
ARCHPROC:
/***********************************************/
/* check that the input parameters are valid */
/***********************************************/
call checkparms
/**************************************/
/* clean off any surrounding spaces */
/**************************************/
DB_DRIVE = left(strip(PARM1), 1) /* Throw away the colon */
DB_NAME = strip(PARM2)
LOG_PATH = strip(PARM3)
LOG_FILE = strip(PARM4)
/******************************************************/
/* Modify LOG_PATH to contain the full log file name */
/******************************************************/
LOG_PATH = LOG_PATH||LOG_FILE
/*********************************************************/
/* Check to see if the log file exists. If not, it is */
/* assumed to have already been archived on a previous */
/* request. Return IBM_RC.OK */
/*********************************************************/
if stream(LOG_PATH, c, 'query exists') = '' then
do
sqluexitrc = IBM_RC.OK
ELINE = 'The file 'LOG_PATH' was assumed to be previously archived'
signal FINISH
end
/******************************************************/
/* Create full path: e.g. c:\userexit\log_hold\testdb */
/******************************************************/
ARCH_PATH = LOG_HOLD'\'DB_NAME
/* Make sure the directory exists if not create it */
call verify_path(ARCH_PATH)
/*****************************************/
/* Copy the log file to the staging path */
/*****************************************/
'xcopy 'LOG_PATH' 'ARCH_PATH
call check_xcopyrc /* Check the rc from XCOPY */
if sqluexitrc <> 0 then
signal FINISH
/****************************************/
/* Add the new file to the archive list */
/****************************************/
lf_name = ARCH_PATH'\'LOG_FILE
call lineout UEXIT_LST, lf_name
call stream UEXIT_LST, c, 'close'
/*************************************/
/* Get the Backup set name of PMTAPE from */
/* the index file. */
/**************************************/
indxfile = DBM_DIR"\PMTINDEX.DAT"
if (LINES(indxfile) =0) then do
next_tape_dr = 1
call LINEOUT indxfile, "/* index file for PMTAPE log archives */",1
call LINEOUT indxfile," 0 "
call LINEOUT indxfile
end
else do
DO WHILE ((LINES(indxfile) =1))
istring=LINEIN(indxfile)
end
call LINEOUT indxfile
blank_loc =POS(' ',istring)
tape_directory = SUBSTR(istring,blank_loc+1)
next_tape_dr = tape_directory + 1
end
/*******************************************************/
/* Check to see if the file containing the number of */
/* log files held exists. If it does, read the number */
/* held and bump it by one, otherwise, assume this is */
/* the first log file to be staged and create the tpf file. */
/*******************************************************/
if stream(NUM_LOGS_HELD, c, 'query exists') = '' then
do
/************/ tpffile=PMT_DIR'\pmtape\DATABASE.tpf'
/* To make sure that the file pointer is at the beginning of the file */
'ERASE 'tpffile' 1>NUL 2>NUL'
/* and create the TPF file. User can add desired options to the .tpf file */
call LINEOUT tpffile,"!Backup",1
/*************/ call LINEOUT tpffile,'/w sc /l BACKUP.LOG /m /n' '"'next_tape_dr'"' '/r /c 0 /g'
call LINEOUT tpffile,'/b /b rhs /s' '"'lf_name'"'
held_logs = 1
tempfile = DBM_DIR'\SQLLIB\TEMP.FIL'
'ERASE ' tempfile '1>NUL 2>NUL'
afile = lf_name
call LINEOUT tempfile, afile next_tape_dr, 1
call LINEOUT tempfile
end
else
do
tpffile=PMT_DIR'\pmtape\DATABASE.tpf'
call LINEOUT tpffile,'/b /b rhs /s' '"'lf_name'"'
rsp_line = linein(NUM_LOGS_HELD) /* Read the record */
held_logs = (substr(rsp_line,1,1)) +1 /*Bump the # logs held by 1 */
/* rexx exec to add a single line to an existing file */
afile = lf_name
tempfile =DBM_DIR'\SQLLIB\TEMP.FIL'
call LINEOUT tempfile, afile next_tape_dr
call LINEOUT tempfile
end
/* Call PMTAPE when no. of archived files is equal to logs to hold */
if held_logs >= LOGS_TO_HOLD then
do
tempfile = DBM_DIR'\SQLLIB\TEMP.FIL'
'COPY 'DBM_DIR'\PMTINDEX.DAT + 'tempfile '1>NUL'
'ERASE 'tempfile' 1>NUL 2>NUL'
call LINEOUT tpffile
call LINEOUT NUM_LOGS_HELD
'pmtape 'PMT_DIR'\pmtape\DATABASE.tpf'
'ERASE ' NUM_LOGS_HELD' 1>NUL 2>NUL'
erase_line = linein(UEXIT_LST, 1)
do while LINES(UEXIT_LST) > 0
'ERASE 'erase_line' 1>NUL 2>NUL'
erase_line = linein(UEXIT_LST)
end /* do */
'ERASE 'erase_line' 1>NUL 2>NUL'
call stream UEXIT_LST, c, 'close'
'ERASE 'UEXIT_LST' 1>NUL 2>NUL'
end
else
do
call lineout NUM_LOGS_HELD, held_logs, 1 /* Write out logs held*/
call stream NUM_LOGS_HELD, c, 'close' /* Close the file */
end
signal FINISH
/************************************************/
/***************************** RETRIEVE A LOG FILE ****************************/
/****************************************************************************/
RETVPROC:
/***********************************************/
/* check that the input parameters are valid */
/***********************************************/
call checkparms
/**************************************/
/* clean off any surrounding spaces */
/**************************************/
DB_DRIVE = left(strip(PARM1), 1) /* Throw away the colon */
DB_NAME = strip(PARM2)
LOG_PATH = strip(PARM3)
LOG_FILE = strip(PARM4)
/****************************************************/
/* Create the well known staging path for log files */
/****************************************************/
ARCH_PATH = LOG_HOLD'\'DB_NAME
call verify_path(ARCH_PATH)
slash_loc =POS('\',ARCH_PATH)
A_PATH = SUBSTR(ARCH_PATH,slash_loc+1)
/* creating temporary storage for retrieving info from tape */
RTRV_DIR = DB_DRIVE':\TAPEDIR'
'MD 'RTRV_DIR' 1>NUL 2>NUL'
/*********************************************************/
/* If the requested log file exists in staging area or temporary storage */
/* copy it to the current log path. Otherwise, call the */
/* tape_retrieve procedure to get the file from tape. */
/*********************************************************/
if stream(ARCH_PATH'\'LOG_FILE, c, 'query exists') <> '' then
do
'XCOPY 'ARCH_PATH'\'LOG_FILE' 'LOG_PATH'*.*'
call check_xcopyrc /* Check the rc from XCOPY */
if sqluexitrc <> 0 then
signal FINISH
end
else do
/*********************************************************/
/* If the requested log file exists in temporary storage area, */
/* copy it to the current log path. Otherwise, call the */
/* tape_retrieve procedure to get the file from tape. */
/*********************************************************/
if stream(RTRV_DIR'\'A_PATH'\'LOG_FILE, c, 'query exists') <> '' then
do
'XCOPY 'RTRV_DIR'\'A_PATH'\'LOG_FILE' 'LOG_PATH'*.*'
call check_xcopyrc /* Check the rc from XCOPY */
if sqluexitrc <> 0 then
signal FINISH
end
else
call tape_retrieve
end
signal FINISH
/*************************** END RETRIEVE A LOG FILE *************************/
/*************************** VERIFY BACKUP PROCEDURE *************************/
/************************/
verify_backup:
/* If the backup fails call PMTAPE again till it is successful */
count = 1
if (LINES(ifile) =0) then do
say "no log file exists"
say "return to caller with error"
exit
end
DO WHILE (count < 9 )
count = count + 1
DO WHILE (LINES(ifile) =1)
istring=LINEIN(ifile)
equals=LEFT(istring,1)
if equals = '=' then do
istring=LINEIN(ifile)
istring=LINEIN(ifile)
equals=LEFT(istring,1)
/* Check log file for unsuccessful */
/* backup file if does call PMTAPE */
if equals <> ' ' then do
call LINEOUT (ifile)
say "Error in backup"
pull hi
'ERASE 'ifile
'PMTAPE 'PMT_DIR'\PMTAPE\DATABASE.TPF'
end
else do
istring=LINEIN(ifile)
istring=LINEIN(ifile)
equals=LEFT(istring,1)
/* Check log file for successful */
/* backup file if none exist call PMTAPE */
if equals = '=' then do
call LINEOUT (ifile)
say "Error in backup"
pull hi
'ERASE 'ifile
'PMTAPE 'PMT_DIR'\PMTAPE\DATABASE.TPF'
end
else exit
end
end
end
call LINEOUT (ifile)
end
return 0
/*************************** END VERIFY BACKUP PROCEDURE *************************/
/**************************** CHECKPARMS PROCEDURE ***********************/
/* Routine for verifying that all parameters passed into SQLUEXIT have some */
/* value. PARM5 is required only for Backup and Restore. */
/***************************************************************************/
checkparms:
if( ((ACTION = 'RESTORE') | (ACTION = 'BACKUP')) & PARM5 = ''),
| (PARM1 = '' | PARM2 = '' | PARM3 = '' | PARM4 = '')
then
do
ELINE = 'One or more input parameters are null.'
sqluexitrc = IBM_RC.PARM
signal FINISH
end
return 0
/******************************* END CHECKPARMS ****************************/
/******************************* INIT PROCEDURE *****************************/
/* Routine for initializing user defined variables and configuration */
/* parameters. */
/****************************************************************************/
INIT:
/*************************/
/* TIMESTAMP INFORMATION */
/*************************/
ODATE = DATE() /* Current date */
OTIME = TIME() /* Current time */
DT = '*** 'ODATE', 'OTIME
/********************************/
/* DEFAULT CONFIGURATION VALUES */
/********************************/
AUDIT = 'Y' /* Log user exit calls by default */
LOGS_TO_HOLD = 9 /* Number of archived logs to hold prior to calling PMTAPE */
PMT_DIR = 'C:' /* The drive where PMTAPE is located */
DBM_DIR="C:" /* The drive where Database Manager is located */
/**************************/
/* USER DEFINED VARIABLES */
/**************************/
EXITDIR = DB_DRIVE'\USEREXIT'
LOG_HOLD = EXITDIR'\LOGHOLD' /* Staging area for log files */
UEXIT_LOG = EXITDIR'\'OPT'.LOG' /* Audit log file */
UEXIT_ERR = EXITDIR'\'OPT'.ERR' /* SQLUEXIT error file */
UEXIT_LST = EXITDIR'\EXIT.LST' /* FILE containing list of log files */
/* to archive */
RETRIEVE_LST = EXITDIR'\RETRIEVE.LST' /* FILE containing list of log files */
/* to retrieve */
REDIRECT_FILE = EXITDIR'\REDIRECT.LST' /* PMTAPE redirection file */
NUM_LOGS_HELD = EXITDIR'\STAGED.LST' /*File containing # archived log files*/
/* currently held. */
ARCH_PATH = '' /* Complete path name to copy log files to/from */
/*****************/
/* RETURN CODES */
/****************/
IBM_RC.OK = 0 /* SUCCESSFUL */
IBM_RC.RES = 4 /* RESOURCE ERROR OCCURRED */
IBM_RC.OPATTN = 8 /* OPERATOR INTERVENTION REQUIRED */
IBM_RC.HARDWARE = 12 /* HARDWARE ERROR OCCURRED */
IBM_RC.DEFECT = 16 /* DEFECT/CONFIGURATION/INSTALLATION ERROR */
IBM_RC.PARM = 20 /* INVALID PARAMETER RECEIVED */
IBM_RC.NOTFOUND = 24 /* REQUIRED FILE(s) NOT FOUND */
IBM_RC.UNKNOWN = 28 /* UNKNOWN ERROR OCCURRED */
IBM_RC.OPCAN = 32 /* OPERATOR CANCELLED */
sqluexitrc = IBM_RC.OK /* VARIABLE USED TO PASS BACK RETURN CODE */
/*************************************/
/* Make sure exit directory exists */
/*************************************/
call verify_path(EXITDIR) /* Path exists?/If not, create it */
VERIFY_DIR = 'TRUE'
ELINE = '' /* Error text */
return 0
/********************************** END INIT *********************************/
/**************************** VERIFY_PATH PROCEDURE ************************/
/* Verifies that the given path exists. If not, it is created. */
/****************************************************************************/
verify_path:
arg CHK_PATH
curdir = directory() /* Save current directory */
/***************************************************************/
/* Separate drive from path and save the remainder of the path */
/***************************************************************/
parse value CHK_PATH with drive '\' path_remain
/*****************************************/
/* Break down path by subdirectory names */
/*****************************************/
i = 1
do while path_remain <> ''
parse value path_remain with path.i '\' path_remain
i = i + 1 /* Subdirectory name index */
end
/**********************************************************************/
/* Rebuild the path one subdirectory at a time checking to see if the */
/* path exist and, if not, create it. */
/**********************************************************************/
build_path = drive /* Build path back up starting at drive letter */
j = 1
do while j < i
build_path = build_path'\'path.j /* Add a subdirectory to path */
newdir = directory( build_path ) /* See if the path already exist */
if( newdir <> build_path ) then do
md_var = 'MKDIR 'build_path
address CMD md_var /* Let OS/2 make the directory */
if (rc <> 0) then do
ELINE = md_var' *** FAILED, <'rc'>'
sqluexitrc = IBM_RC.UNKNOWN
signal FINISH
end
end
j = j + 1 /* Bump subdirectory name index */
end
call directory curdir /* Return to the original directory */
return 0
/******************************* END VERIFY_PATH ****************************/
/****************************** CHECKRC PROCEDURE**************************/
/* Check the return code from the PMTAPE Software and map to the */
/* expected DBM return codes. */
/****************************************************************************/
checkrc:
pmtape_rc = rc
Select
when pmtape_rc = 0 then do /* Successful */
sqluexitrc = IBM_RC.OK;
return;
end
OTHERWISE do /* UNKNOWN ERROR */
ELINE= 'PMTAPE software returned ERROR <'pmtape_rc'>'
sqluexitrc = IBM_RC.UNKNOWN;
return;
end
end
return
/**************************** END CHECKRC PROCEDURE ***********************/
/*************************** CHECK_XCOPYRC PROCEDURE *********************/
/* Check the return code from OS/2's XCOPY command and map to the expected */
/* DBM return codes. */
/****************************************************************************/
check_xcopyrc:
os2_rc = rc
Select
when os2_rc = 0 then do /* Successful */
sqluexitrc = IBM_RC.OK;
return;
end
when os2_rc = 1 then do
ELINE= 'OS/2 XCOPY ERROR <1>: No files found to Backup or Restore'
sqluexitrc = IBM_RC.NOTFOUND;
return;
end
when os2_rc = 2 then do
ELINE= 'OS/2 XCOPY ERROR <2>: Busy files not Backed up or Restored'
sqluexitrc = IBM_RC.UNKNOWN;
return;
end
when os2_rc = 3 then do
ELINE= 'OS/2 XCOPY ERROR <3>: Command Terminated by user'
sqluexitrc = IBM_RC.OPCAN;
return;
end
when os2_rc = 4 then do
ELINE= 'OS/2 XCOPY ERROR <4>: Command Terminated due to error'
sqluexitrc = IBM_RC.UNKNOWN;
return;
end
OTHERWISE do /* Unknown error */
ELINE= 'OS/2 XCOPY command returned ERROR <'os2_rc'>'
sqluexitrc = IBM_RC.UNKNOWN;
return;
end
end
return
/************************* END CHECK_XCOPYRC PROCEDURE *******************/
/************************ REMOVE TEMP STORAGE PROCEDURE ******************/
/*************************************************************************/
/* Procedure to remove temporary storage directory */
/*************************************************************************/
rmvdirs:
newdir = directory(DB_DRIVE":\TAPEDIR\USEREXIT")
if newdir = DB_DRIVE":\TAPEDIR\USEREXIT" then
do
/* Save DIR command output in a file */
'DIR 'DB_DRIVE':\TAPEDIR\USEREXIT\LOGHOLD>'DBM_DIR'\SQLLIB\REMOVE'
dirfile = DBM_DIR"\SQLLIB\REMOVE"
if (LINES(dirfile) =0) then do
say "no index file exists"
exit
end
/* Skip lines till you get to the directory names */
DO 7
istring=LINEIN(dirfile)
end
empty=0
istring=LINEIN(dirfile)
/* Get the directory name */
blank_loc =POS(' ',istring)
tdir = LEFT(istring,blank_loc-1)
if tdir = "" then
do
empty = 1
end
else do /* Erase the directory */
'CD 'DB_DRIVE':\TAPEDIR\USEREXIT\LOGHOLD\'tdir
'DIR'
'ERASE *.LOG'
'CD ..'
'RD 'tdir
end /* else */
/* Continue deleting subdirectories until */
/* all are deleted */
DO WHILE((LINES(dirfile) =1) & (empty=0))
istring=LINEIN(dirfile)
blank_loc =POS(' ',istring)
tdir = LEFT(istring,blank_loc-1)
if tdir = "" then
empty = 1
else do
'CD 'DB_DRIVE':\TAPEDIR\USEREXIT\LOGHOLD\'tdir
'DIR'
'ERASE *.LOG'
'CD ..'
'RD 'tdir
end /* else */
end /* while */
'CD ..'
'RD LOGHOLD'
'CD ..'
'RD USEREXIT'
'CD ..'
'RD TAPEDIR'
end /* if */
return 0
/****************************************************************************/
/******************** END REM TEMP STORAGE PROCEDURE ************************/
/*************************** TAPE_RETRIEVE PROCEDURE ***********************/
/* Call PMTAPE to retrieve the requested log file from tape. */
/****************************************************************************/
tape_retrieve:
/********************************/
/* Clear the RETRIEVE_LST file */
/********************************/
'ERASE 'RETRIEVE_LST' 1>NUL 2>NUL'
/*****************************************/
/* Create a new list file to call PMTAPE */
/*****************************************/
lf_name = ARCH_PATH'\'LOG_FILE
call lineout RETRIEVE_LST, lf_name
call stream RETRIEVE_LST, c, 'close'
/*****************************************/
/* Build the redirection file for PMTAPE */
/* This allows us to restore the file to */
/* a path other than the origin. */
/*****************************************/
'ERASE 'REDIRECT_FILE' 1>NUL 2>NUL' /* Clear redirection file first */
call lineout REDIRECT_FILE, lf_name
call lineout REDIRECT_FILE, LOG_PATH||LOG_FILE
call stream REDIRECT_FILE, c, 'close'
/*******************************************/
/* Get drive name from the pmtindex file */
/******************************************/
/* rexx code to read an index file and get direcroy info */
findpath = lf_name /* string being searched for in pmtindex.dat */
indxfile = DBM_DIR"\PMTINDEX.DAT"
if (LINES(indxfile) =0) then do
say "no index file exists"
say "return to caller with error"
exit
end
not_found = 1
DO WHILE ((LINES(indxfile) =1) & (not_found))
istring=LINEIN(indxfile) /* last line */
blank_loc =POS(' ',istring)
temppath = LEFT(istring,blank_loc-1)
if (temppath=findpath) then not_found =0
end
call LINEOUT indxfile
/* Get the Backup set name where */
/* the database is stored on PMTAPE */
tape_directory = SUBSTR(istring,blank_loc+1)
dot_loc =POS('.',temppath)
t2file = LEFT(temppath,dot_loc-10)
call verify_path(t2file) /* Make sure the directory exists */
/*****************************************/
/* Build the .tpf file and Call PMTAPE to get the file from tape */
/*****************************************/
slash_loc =POS('\',lf_name)
lf2_name = SUBSTR(lf_name,slash_loc+1)
call rmvdirs
tpffile=PMT_DIR'\pmtape\database.tpf'
tpffile2=PMT_DIR'\pmtape\retrv.tpf'
'ERASE 'tpffile' 1>NUL 2>NUL'
'ERASE 'tpffile2' 1>NUL 2>NUL'
call LINEOUT tpffile,"!Restore",1
call LINEOUT tpffile,"/w socnf /l "PMT_DIR"\PMTAPE\RESTORE.LOG i /m /t "LOG_PATH" /p 2 /k 0 /o 2"
call LINEOUT tpffile,"/b /b rhs "
call LINEOUT tpffile,"/s "'"'tape_directory"\"lf2_name""""
call LINEOUT tpffile2,"!Restore",1
call LINEOUT tpffile2,"/w socnf /l "PMT_DIR"\PMTAPE\RESTORE.LOG i /m /t "RTRV_DIR" /p 2 /k 1 /o 2"
call LINEOUT tpffile2,"/b /b rhs /q"
call LINEOUT tpffile2,"/s "'"'tape_directory"\*"""
call LINEOUT tpffile
call LINEOUT tpffile2
'PMTAPE 'PMT_DIR'\PMTAPE\DATABASE.TPF'
'PMTAPE 'PMT_DIR'\PMTAPE\RETRV.TPF'
call checkrc
if sqluexitrc <> IBM_RC.OK then
signal FINISH
return
/************************* END TAPE_RETRIEVE PROCEDURE *********************/
/******************************* HALT PROCEDURE ****************************/
/* Called when a CTRL-C is received */
/****************************************************************************/
HALT:
ELINE = "USER TERMINATION"
sqluexitrc=IBM_RC.OPCAN
signal FINISH
/***************************** END HALT PROCEDURE **************************/
/****************************** FINISH PROCEDURE ****************************/
/* Check for interactive mode and select appropriate exit routine. */
/* If in interactive mode, it allows the User to determine what return code */
/* to return back to the Database Manager. */
/****************************************************************************/
FINISH:
say DT /* Date/time */
say PARMS /* Passed in parameters */
say ''
say ELINE /* Error text */
if sqluexitrc = 0 then
signal EXITOK
else do
pull hi
signal EXITERR
end
/**************************** END FINISH PROCEDURE **************************/
/****************************** EXITERR PROCEDURE **************************/
/* Procedure handles error conditions for SQLUEXIT.It always logs the error */
/* and configuration in an error file. */
/***************************************************************************/
EXITERR:
if VERIFY_DIR = 'TRUE' then
do
call lineout UEXIT_ERR, ' '
/** Timestamp this error in the error file **/
RT = '***** SQLUEXIT ERROR ON 'ODATE' @ 'OTIME
call lineout UEXIT_ERR, RT
/** Output the SQLUEXIT configuration to the error file **/
RT = ' SQLUEXIT CONFIGURATION: 'AUDIT
call lineout UEXIT_ERR, RT
/** Output the parameters received to the error file **/
call lineout UEXIT_ERR, PARMS
/** Output the Error message to the error file **/
call lineout UEXIT_ERR, ELINE
/** Output the error code being returned to the DBM in the error file **/
RT = ' ERROR CODE RETURNED TO DBM: <'sqluexitrc'>'
call lineout UEXIT_ERR, RT
if AUDIT = 'Y' then /* Auditing enabled? */
do
call lineout UEXIT_LOG, ELINE
RT = ' RETURNED DBM A VALUE OF <'sqluexitrc'>'
call lineout UEXIT_LOG, RT
call lineout UEXIT_LOG, ' '
end
say RT
end
else
say ' Returned DBM a value of <'sqluexitrc'>'
exit sqluexitrc
/**************************** END EXITERR PROCEDURE ************************/
/****************************** EXITOK PROCEDURE ***************************/
/* Routine handles normal exits from SQLUEXIT. */
/****************************************************************************/
EXITOK:
RT = ' Returned DBM a value of <'sqluexitrc'>'
if AUDIT = 'Y' then
do
call lineout UEXIT_LOG, RT
call lineout UEXIT_LOG, ' '
end
say RT
exit sqluexitrc
/**************************** END EXITOK PROCEDURE *************************/