Importing and Exporting Data
This section provides detailed information on importing and exporting data using the following BUTIL commands: Copy, Load, Recover, and Save.
Copy
The COPY command copies the contents of one MicroKernel file to another. Copy retrieves each record in the input data file and inserts it into the output data file. The record size must be the same in both files. After copying the records, COPY displays the total number of records inserted into the new data file.
*Note: Copy performs in a single step the same function as a Recover command followed by a Load command.
Using the COPY command, you can create a data file that contains data from an old file, but has new key characteristics.
1
Use the Create command to create an empty data file with the desired key characteristics (key position, key length, or duplicate key values).
or
Use Clone to create an empty data file using the characteristics of an existing file.
2
Use the COPY command to copy the contents of the existing data file into the newly created data file.
Format
butil -copy sourceFile outputFile [/O< owner1 | *>
[/O<owner2 | *>]] [/UIDuname /PWDpword [/DBdbname]]
/Oowner1
/Oowner2
/UID<name>
/UIDuname
/PWD<word>
/PWDpword
Specifies the password for the user who is identified by uname. Pword must be supplied if uname is specified.
/DB<name>
/DBdbname
Example
The following command copies the records in COURSE.MKD to NEWCRS.MKD. The COURSE.MKD input file does not require an owner name, but the NEWCRS.MKD output file uses the owner name Pam.
butil -copy course.mkd newcrs.mkd /O /OPam
If you omit the first /O from this example, the utility assumes that the owner name Pam belongs to the input data file, not the output data file.
Load
The LOAD command inserts records from an input ASCII file into a file. The input ASCII file can be a single file or an extended file (the base file plus several extension files). Load performs no conversion on the data in the input ASCII file. After the utility transfers the records to the data file, it displays the total number of records loaded.
*Note: The LOAD command opens the output file in Accelerated mode; during a load operation, the database engine does not log the file. If you are using archival logging, back up your data files again after using the LOAD command.

Extended files: If the utility finds the next extension file, it continues the load process. Do not delete any extension file created earlier by the SAVE and RECOVER commands. If the file has three extensions and the user deletes the second one, LOAD stops loading records after processing the first extension file.

If SAVE or RECOVER created three extension files and a fourth one exists from a previous SAVE or RECOVER, LOAD reads the records from the fourth extension and inserts them into the database engine file. If a fourth file exists, then you need to delete it before starting the LOAD process.
Before running the LOAD command, you must create the input ASCII file and the data file. You can create the input ASCII file using a standard text editor or an application; the input ASCII file must have the required file format (see Importing and Exporting ASCII File Format). You can create the data file using either the  Create or the  Clone command.
Format
butil -load unformattedFile outputFile [/O<owner |*>] [/UIDuname /PWDpword [/DBdbname]]
/Oowner
/UID<name>
/UIDuname
/PWD<word>
/PWDpword
Specifies the password for the user who is identified by uname. Pword must be supplied if uname is specified.
/DB<name>
/DBdbname
Example
The following example loads sequential records from the COURSE.TXT file into the COURSE.MKD file. The owner name of the COURSE.MKD file is Sandy.
butil -load course.txt course.mkd /OSandy
Recover
The RECOVER command extracts data from a MicroKernel file and places it in an ASCII file that has the same format as the input ASCII file that the Load command uses. This is often useful for extracting some or all of the data from a damaged MicroKernel file. The RECOVER command may be able to retrieve many, if not all, of the file’s records. You can then use the LOAD command to insert the recovered records into a new, undamaged MicroKernel file.
*Note: The Maintenance utility performs no conversion on the data in the records. Therefore, if you use a text editor to modify an output file containing binary data, be aware that some text editors may change the binary data, causing the results to be unpredictable.
Format
BUTIL -RECOVER sourceFile unformattedFile [/O<owner |*>]
[/Q] [/J] [/I] [/UIDuname /PWDpword [/DBdbname]]
/Oowner
Indicates FORWARD reading of the file. Although the default is forward reading, you can use this option to indicate FORWARD and BACKWARD reading. This means that if you specify both /I and /J, respectively, the utility reads the file forward until it fails. Then it starts at the end of the file and reads backwards until it reaches the record that failed previously or encounters another failure.

If you specify /J first, the utility reads backwards and then reads forward.
/UID<name>
/UIDuname
/PWD<word>
/PWDpword
Specifies the password for the user who is identified by uname. Pword must be supplied if uname is specified.
/DB<name>
/DBdbname
For each record in the source file, if the RECOVER command receives a variable page error (Status Code 54), it places all the data it can obtain from the current record in the unformatted file and continues the recovery process.
The utility produces the following messages:
Example
The following example extracts records from the COURSE.MKD file and writes them into the COURSE.TXT file.
butil -recover course.mkd course.txt
Save
The SAVE command retrieves records from a MicroKernel file using a specified index path and places them in an ASCII file that is compatible with the required format for the load command. You can then edit the ASCII file and use the LOAD command to store the edited data in another data file. (See Importing and Exporting ASCII File Format for more information about the ASCII file format.)
Save generates a single record in the output ASCII file for each record in the input data file. Upon completion, SAVE displays the total number of records saved.
*Note: The Maintenance utility performs no conversion on the data in the records. Therefore, if you use a text editor to modify an output file containing binary data, be aware that some text editors may change the binary data, causing the results to be unpredictable.
Format
butil -save sourceFile unformattedFile [Y indexFile | N <keyNumber | -1>] [/O<owner1 | *> [/O<owner2 | *>]] [/Q] [/J] [/I] [/UIDuname /PWDpword [/DBdbname]]
The fully qualified name of an external index file by which to save records if you do not want to save records using the default of the lowest key number.
The key number (other than 0) by which to save records if you do not want to save records using the default of the lowest key number.
/Oowner1
/Oowner2
Indicates FORWARD reading of the file. Although the default is forward reading, you can use this option to indicate FORWARD and BACKWARD reading. This means that if you specify both /I and /J, respectively, the utility reads the file forward until it fails. Then it starts at the end of the file and reads backwards until it reaches the record that failed previously or encounters another failure.

If you specify /J first, the utility reads backwards and then reads forward.
/UID<name>
/UIDuname
/PWD<word>
/PWDpword
Specifies the password for the user who is identified by uname. Pword must be supplied if uname is specified.
/DB<name>
/DBdbname
The utility produces the following messages:
Examples
The following two examples illustrate how to use the SAVE command to retrieve records from a data file.
This example uses a NEWCRS.IDX external index file to retrieve records from the COURSE.MKD file and store them in an unformatted text file called COURSE.TXT:
butil save course.mkd course.txt newcrs.idx
The following example retrieves records from the COURSE.MKD file using key number 3 and stores them in an unformatted text file called COURSE.TXT:
butil -save course.mkd course.txt n 3