Name: BACKUP Shortest: BAC
Family: Command Category: Data Integrity
Description: Use the BACKUP command to copy the data and/or structure of a database to floppy disks or another directory on your hard disk.

Syntax

BACKUP syntax diagram

Options

ALL
Backs up the entire structure and data of the current database.

DATA
Backs up just the data of the current database.

FOR tblname
Specifies a single table to back up. If this clause is not used, all tables in the database are backed up.

FOR tblview
Specifies a table or view to back up. If this clause is not used, all tables and views in the database are backed up.

ORDER BY clause
Sorts rows of data. For more information, see the "ORDER BY" entry.

STRUCTURE
Backs up just the structure of the current database.

USING collist
Specifies the columns to back up and in what order to back them up. USING ALL backs up all columns in the order they are defined in the table.

WHERE clause
Limits rows of data. For more information, see the "WHERE" entry.

About the BACKUP Command

The BACKUP command backs up data and/or structure to a backup file in the ASCII delimited format, which you can edit with a text editor. For example, you can restore the structure or data from one database to a new database, then edit the backup file with a text editor to change the database name to a new one.

BACKUP does not back up computed-column values; the values will be computed when the database is restored.

BACKUP does not change the data or the structure in the original database. Use the RESTORE command to restore your data.

If a BACKUP command is included in a transaction when transaction processing is on, the backup cannot be rolled back.

The BACKUP command creates a file with a .LOB extension for binary large objects, and a file for the data and/or structure.

SET Special Characters and Operating Conditions

To properly restore a database, BACKUP places the settings for the SET special characters and operating conditions used in the database at the beginning of the ASCII backup file. Within the backup file, object names, such as table names, will be enclosed within the IDQUOTES character, the current setting for DELIMIT is used to separate values, text strings are enclosed in the current setting of QUOTES, and the current value of WIDTH affects the width of data lines in the backup file.

Following are three tips that will ensure your database is restored from a backup properly:

Backing Up to Disks

When you back up data to floppy disks, use blank formatted disks. The backup file can span multiple floppy disks. If BACKUP fills a disk, it prompts you to enter a new disk before continuing.

Note: So that you don't mix up the disks, label and number them as you remove them.

If you are backing up to a hard disk and the disk becomes full, press [Esc] to stop the backup. You can either free up hard disk space before backing up again, or back up to floppy disks.

It is worth noting that even when using R:BASE for Windows you will need to issue this command at the R> Prompt or via a command file.

Using the BACKUP Command

When you back up your data, use the OUTPUT command to specify the filename of the backup. The BACKUP command does not erase files on a floppy disk, but overwrites a file if the filename you specify already exists on the disk. For examples of how to use the OUTPUT command, see the OUTPUT reference.

You can back up a database in one of the following ways:

Following is information about each method.

Backing Up the Structure and Data

Use the BACKUP ALL command to back up the structure and data in the current database, or the structure and data for a specific table. You can back up a database structure and data to separate files if you prefer two smaller files to one large file. BACKUP writes all the commands necessary to define the database or table, starting with the CREATE SCHEMA AUTHORIZATION dbname command near the beginning of the file.

BACKUP uses the LOAD command to load the data.

If the database is protected by the database owner's user identifier, BACKUP ALL requires the owner's user identifier, which R:BASE places in the backup file to ensure that the restored database file continues to be protected. Keep the backup file from unauthorized users to ensure the database file remains protected.

Backing Up the Structure Only

Use the BACKUP STRUCTURE command to back up just the structure of the current database, or the structure of a specific table. BACKUP writes all the commands necessary to define the database or table, starting with the CREATE SCHEMA AUTHORIZATION dbname command near the beginning of the file. Any collating or case-folding table defined by the database owner is automatically preserved.

Keep the backup file from unauthorized users to ensure the database file remains protected. If the database is protected by an owner's user identifier, BACKUP STRUCTURE requires the owner's user identifier, which R:BASE places in the backup file to ensure that the restored database file continues to be protected.

Backing Up Data Only

Use the BACKUP DATA option to back up the data in the current database or the data in a specific table. BACKUP uses the LOAD command to load the data. Also, use the BACKUP DATA option to back up any custom information stored in R:BASE system tables such as Forms, Reports, Labels and Stored Procedures.

Examples

The following command lines back up the structure and data for every table in the open database to the MYDB.BUP file on drive A:, redirect the output to the screen, and close the file.

OUTPUT a:mydb.bup
BACKUP ALL
OUTPUT SCREEN

The command lines below back up the data and structure of the customer table to the CUSTOMER.BUP file, limit the rows to those that are dated after 10/1/89, and order the rows by custid.

OUTPUT customer.bup
BACKUP ALL FOR customer WHERE datecol > 10/1/89 ORDER BY custid
OUTPUT SCREEN

The following command lines back up the structure of the customer table to the CUSTSTRC.BUP file, redirect the output to the screen, and close the file.

OUTPUT custstrc.bup
BACKUP STRUCTURE FOR customer
OUTPUT SCREEN

The following command lines back up the data from the producttable to the PRODUCT.BUP file, redirect the output to the screen, and close the file.

OUTPUT product.bup
BACKUP DATA FOR product
OUTPUT SCREEN

The following command lines show how to transfer a form to a new database. The first five command lines open the olddb database, set the null value to -0-, create the TEMPFORM.DAT file on drive D:, back up the data from the sys_forms2 table that contains the definition of the oldform form, and redirect the output to the screen. Command lines six through eight open the newdb database in order to transfer the oldform form definition (the database you open must not have a form named oldform), set the null value to -0-, and load the form definition from the backup file into the sys_forms2table.

CONNECT olddb
SET NULL -0-
OUTPUT d:tempform.dat
BACKUP DATA FOR SYS_FORMS2 WHERE SYS_FORM_NAME = 'oldform'
OUTPUT SCREEN
CONNECT newdb
SET NULL -0-
RUN d:tempform.dat