Kbase P20383: How to dump records from a corrupt table using 4GL
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  28/12/2010 |
|
Status: Verified
GOAL:
How to dump records from a corrupt table using 4GL
GOAL:
How to dump data around corrupt database blocks
FACT(s) (Environment):
Progress 9.x
OpenEdge 10.x
All Supported Operating Systems
FIX:
The following program is to be used on version 9 databases. Copy the follow program to a file and name the file dumprec.p. Note that the beginning of the program has comments explaining how you should use the program.
/**************************** dumprec.p ***********************************
The purpose of this program is to dump data from a database, 1 table at a time. It creates 2 files, tablename.d and RECID.txt. If there is corruption in the table the program will fail when it hits the corrupted block.
At this point you can modify the program to continue the dump after the spot where the corruption was found.
If the program fails because of corruption, follow these steps:
1) Open the file tablename.d and check the last record entry. If the record entry is incomplete, delete the entry.
2) Open the RECID.txt file and note the last complete entry.
3) Take this number and divide it by the records-per-block value
4) Take this value, dropping any digits to the right of the decimal point & multiply this whole number by the records-per-block value
5) Now add the records-per-block value to this number. This step will allow the program to resume the dump process at the next block.
6) In the main program below modify the line
REPEAT iRecID = 1 TO (TotalBlocks * RecPerBlock):
to
REPEAT iRecID = NEW-NUMBER TO (TotalBlocks * RecPerBlock):
For example: Lets say your number at the end of the RECID.txt file is 1239036
and the records-per-block = 32.
Steps
3) 1239036 / 32 = 38719.875
4) 38719 * 32 = 1239008
5) 1239008 + 32 = 1239040
6) REPEAT iRecID = 1239040 TO (TotalBlocks * RecPerBlock):
Now run the program again to continue the table dump. If there is corruption in other database blocks you may have to repeat the above steps until the program finishes.
******************************************************************************/
DEF VAR iRecID AS INT.
DEF VAR TotalBlocks AS INT.
DEF VAR RecPerBlock AS INT.
DEF VAR iTemplate AS RECID.
DEF VAR TableName AS CHAR.
DEF STREAM sRecid.
DEF STREAM sDump.
/******************************************************************************
Below you need to enter the table name and the number of records per block for the storage area. You can get the records per block from the databasename.st file.
*******************************************************************************/
&SCOP TableName customer
/******************************************************************************/
OUTPUT STREAM sRecid TO RECID.txt APPEND.
OUTPUT STREAM sDump TO {&TableName}.d APPEND.
/****** FIND which storage area the TABLE IS located IN. ******/
FIND FIRST _File WHERE _File-Name = "{&TableName}" NO-LOCK.
FIND FIRST _StorageObject WHERE _Object-number = _File-Number NO-LOCK.
FIND FIRST _Area WHERE _StorageObject._Area-number = _Area._Area-number.
FIND FIRST _AreaStatus WHERE _AreaStatus-AreaNum =
_StorageObject._Area-number NO-LOCK.
ASSIGN TotalBlocks = _AreaStatus-Hiwater.
ASSIGN RecPerBlock = EXP(2,_Area-recbits).
MESSAGE "Dumping Table: {&TableName}~nLocated on Storage Area " + string(_Area._Area-number) + "~nwith:" recperblock " records per block." VIEW-AS ALERT-BOX.
/********* Find the record template *********/
FIND FIRST _file WHERE _file-name = "{&TableName}" NO-LOCK.
ASSIGN iTemplate = _Template.
/******Main program which dumps the record ID and data from the table******/
REPEAT iRecID = 1 TO (TotalBlocks * RecPerBlock):
FIND {&TableName} WHERE RECID({&TableName}) = iRecID NO-LOCK
NO-ERROR.
IF RECID({&TableName}) <> iTemplate AND AVAILABLE({&TableName}) THEN
DO:
PUT STREAM sRecid UNFORMATTED RECID({&TableName}) SKIP.
EXPORT STREAM. sDump {&TableName}.
END.
END.
OUTPUT STREAM sDump CLOSE.
OUTPUT STREAM sRecid CLOSE.
MESSAGE "Dump Complete" VIEW-AS ALERT-BOX..