Subject: disk_struct.4gl From: Peter Tashkoff Date: Fri, 18 Jul 1997 11:29:13 +1200 Hi This is a copy of the program that comprehends irregularly numbered dbspace IDs. Please ditch the earlier version. rgds Peter ------------------- DISK_S~1.4GL follows -------------------- --------------------------------------------------------- -- File name : disk_struct.4gl -- Author : Peter Tashkoff -- Written : Thu Jul 10 1997 --------------------------------------------------------- -- Brief : Gets the disk structure for -- Descr : the current instance -- : Presently does not automatically handle -- : page unit size for blobs as I have not been -- : able to determine where in sysmaster this is -- : held. Comments welcome. -- : I have designed the program so that it can -- : be run nightly from cron to provide -- : a quick start for disaster recovery. -- : It is also useful when setting up copies of -- : an instance for purposes of backup testing -- : or replication. -- : Handles situations where initial Chunk id < -- : added chunkid. --------------------------------------------------------- --Modification Log: please ensure this is kept up-to-date --Who When SWR Description --------------------------------------------------------- --------------------------------------------------------- database sysmaster main define fv_reportname char(60) if num_args() > 0 then let fv_reportname = arg_val(1) else options prompt line 17 end if call build_script(fv_reportname) end main ##################################################### # Function: build_script # Descr : Cats together a shell script # author : tashkop Thu Jul 10 1997 # Receives: nil # Returns : nil ##################################################### function build_script(fv_reportname) define fr_syschunks record like syschunks.* define fr_sysdbspaces record like sysdbspaces.* define fv_reportname char(60) define fv_space_name char(80) set isolation to dirty read --set the report up if fv_reportname is null then display " disk_struct.4gl " at 9,15 display " This program will produce a shell script of" at 10,15 display " onspaces commands to set up a copy of " at 11,15 display " the current instance." at 12,15 display " Developed and tested in 7.x " at 13,15 prompt " Enter a filename to report to: " for fv_reportname end if call create_temp_table() --holds any irregularly numbered chunks start report script_report to fv_reportname --Get the chunks in ascending order declare scurs_dbspaces cursor for select * from sysdbspaces, syschunks where sysdbspaces.dbsnum = syschunks.dbsnum order by syschunks.chknum let fv_space_name = null foreach scurs_dbspaces into fr_sysdbspaces.*, fr_syschunks.* call script_report( fr_sysdbspaces.*, fr_syschunks.*, fv_reportname, fv_space_name) end foreach --now get any chunks that have been created --with irregular numbering. declare scurs_tmp_chunks cursor for select * from sysdbspaces, tmp_syschunks where sysdbspaces.dbsnum = tmp_syschunks.dbsnum order by tmp_syschunks.chknum let fv_space_name = null foreach scurs_tmp_chunks into fr_sysdbspaces.*, fv_space_name, fr_syschunks.* call script_report( fr_sysdbspaces.*, fr_syschunks.*, fv_reportname, fv_space_name) end foreach finish report script_report end function -- build_script ##################################################### # Function: script_report # Descr : Writes out the lines # author : tashkop Thu Jul 10 1997 # Receives: syschunks record, sysdbspaces record, reportname # Receives: and for irregularly numbered chunks, # Receives: the dbspace name. # Returns : ##################################################### report script_report(rr_sysdbspaces, rr_syschunks, rv_reportname, rv_space_name) define rr_syschunks record like syschunks.* define rr_sysdbspaces record like sysdbspaces.* define rv_reportname char(60) define rv_server char(60) define rv_loginid char(8) define rv_scriptline char(175) define rv_pagesize integer define rv_temp char(4) define rv_dbspace_type char(20) define rv_pageunit char(20) define rv_create_or_add char(20) define rv_space_name char(80) define rv_drop_line char(175) define rv_need_ontape smallint output page length 12 top margin 0 bottom margin 0 left margin 0 format first page header select USER into rv_loginid from systables where tabid = 99 let rv_server = fgl_getenv("INFORMIXSERVER") select trunc( sh_pagesize / 1024 ) into rv_pagesize from sysshmvals print "#!/bin/ksh" print "# ", rv_loginid clipped," ", date print "# This script defines the structure of the " print "# ", rv_server clipped, " instance of ODS" print "# as at ", date, " ", time print "# Script is in onspaces format to allow the " print "# disaster recovery of dbspaces or to " print "# set up a backup or replicated instance" print "# If neccessary, ontape is invoked at completion" print "# ensure archive path is set to /dev/null" print let rv_need_ontape = false on every row let rv_drop_line = null --used 2nd time around to drop chunks --Cat together an onspaces command --Blobspace or dbspace? if rr_sysdbspaces.is_blobspace = 0 then let rv_dbspace_type = " -d " let rv_pageunit = "" else let rv_dbspace_type = " -b " let rv_pageunit = "-g AddPageUnitSize" end if --Temp dbspace? if rr_sysdbspaces.is_temp != 0 then let rv_temp = " -t " else let rv_temp = "" end if if rv_space_name is null then --First time through, normal handling --Is this an addition or a create? case when rr_syschunks.chknum = rr_sysdbspaces.fchunk --New Dbspace let rv_space_name = rr_sysdbspaces.name let rv_create_or_add = " -c ", rv_dbspace_type when rr_syschunks.chknum < rr_sysdbspaces.fchunk --Chunk added in a non-linear fashion. --need special handling --(Create chunk under a pseudonym, then reallocate later.) let rv_create_or_add = " -c ", rv_dbspace_type let rv_space_name = rr_sysdbspaces.name clipped , "_", rr_syschunks.chknum using "<<<<" --keep a record of the pseudo chunks insert into tmp_syschunks values ( rv_space_name, rr_syschunks.*) let rv_need_ontape = true let rv_drop_line = "#PLACEHOLDER FOR IRREGULARLY NUMBERED CHUNK" otherwise -- a normal additional chunk. let rv_space_name = rr_sysdbspaces.name let rv_create_or_add = " -a " let rv_temp = "" --not part of the add syntax. end case else -- second time through, reallocating chunks as neccessary --this is to drop the placeholder chunk let rv_drop_line = "onspaces -d ", rv_space_name clipped, " -y " --This sets up the adding back of the record. let rv_space_name = rr_sysdbspaces.name let rv_create_or_add = " -a " let rv_temp = "" --not part of the add syntax. end if --Put together a line let rv_scriptline = "onspaces ", rv_create_or_add clipped, " ", rv_space_name clipped, " ", rv_temp clipped, " ", rv_pageunit clipped, " -p ", rr_syschunks.fname clipped , " " , " -o ", rr_syschunks.offset * rv_pagesize using "<<<<<<<<<&" , " -s ", rr_syschunks.chksize * rv_pagesize using "<<<<<<<<<&" --Take account of mirroring if rr_sysdbspaces.is_mirrored != 0 then let rv_scriptline = rv_scriptline clipped, " ", " -m ", rr_syschunks.mfname clipped , " ", rr_syschunks.moffset * rv_pagesize using "<<<<<<<<<&" end if --Print the line if rv_drop_line then print rv_drop_line clipped let rv_drop_line = null end if print rv_scriptline clipped on last row if rv_need_ontape then print "ontape -s " end if end report -- script_report ##################################################### # Function: create_temp_table # Descr : Holds any chunks created in irregular order # Descr : First field is an 80 char placeholder # author : tashkop Mon Jul 14 1997 # Receives: nil # Returns : nil ##################################################### function create_temp_table() select " " as space_name, syschunks.* from syschunks where 1=2 into temp tmp_syschunks end function -- create_temp_table