About gbak Files - Firebird

The gbak utility analyzes and decomposes Firebird database files, storing cleaned metadata and data separately, in a compact format. A backup made with gbak is not a database file and will not be recognized by the server. In order to become useable, it must be restored to a Firebird format that is readable by the server, using the version of gbak that corresponds to the version of Firebird server that is running.

When restoring its files back to database format, gbak performs validation of both metadata and data before using query-language commands internally to reconstruct the database and repopulate it with its data.

If corrupt structures or data are detected, gbak stops restoring and reports the condition. Its ability to analyze problems makes it an invaluable helper when recovery of broken databases is being attempted.

gbak’s Other Talents

gbak also performs an important sequence of other utility tasks in the course of analyzing, storing, and restoring your database. Some are automatic; others can be requested by means of switches in the command-line call when you invoke the program.

  • gbak performs garbage collection on outdated records during backup—an optional switch, enabled by default. If enabled, this housekeeping occurs even if you don’t restore the backup and begin working with a fresh file. Note, however, that running gbak doesn’t pack the database that it is backing up—run a full sweep to do that.

Restore tasks can include

  • Balancing indexes, to refresh the performance capability of your database.
  • Reclaiming space occupied by deleted records and packing the remaining data. This often reduces database size and improves performance by “packing” data.
  • Optionally changing the database page size on restore.
  • Changing the database owner. This is optional—but watch out! It can happen by accident if you are not careful.
  • Upgrading an InterBase database to Firebird or a lower version Firebird database to a higher version (i.e., upgrading the on-disk structure [ODS]).
  • Splitting the database into multiple files or resizing existing multiple files. This is optional.
  • Distributing a multi-file database across multiple disks. This is optional.

Backup and restore also have important roles to play in the unfortunate event that databases become corrupt.

Upgrading the On-Disk Structure

New major releases of the Firebird server are likely to feature changes that alter the on-disk structure (ODS). If the ODS has changed and you want to take advantage of any new Firebird features, upgrade your databases to the new ODS. A new server version can access databases created with some previous versions, but it will not be able to share any of its new features with an older database with a lower ODS.

You can use most Firebird 1.0.x databases directly with Firebird 1.5, even though the ODS of v.1.5 (10.1) is a point higher than that of v.1.0.x (10.0). All the same, it isrecommended that you do follow the upgrade procedure on your databases when you do the transition from 10.0 to 10.1, to take advantage of the performance increase made possible by the v.1.5 indexing of system tables.

To upgrade existing databases to a new ODS, perform the following steps:

  1. Before installing the new ODS version of Firebird, back up databases using the old version of gbak.
  2. Install the new version of the Firebird server as described in Chapter installation.
  3. Once the new version is installed, restore the databases using the gbak that is installed along with it, in the bin directory beneath the Firebird root.

Dialect 1 Databases

A dialect 1 database remains dialect 1 when it is restored. The database remains limited to the language features of InterBase 5, although some restrictions apply to a dialect 1 database under the new ODS that do not apply to InterBase 5. For example, Firebird has a number of new reserved words that will be “illegal” in a dialect 1 database.

To diverge from the topic slightly, it is possible to change the dialect of a restored dialect 1 database to dialect 3, using the gfix tools discussed in the next chapter. However, migration is not as simple as that. Language is not the only thing about the two dialects that has differences. Data type differences are at least as important, if not more so.

For example, fixed numeric domains and columns retain their old attributes when the database is changed to dialect 3. NUMERIC and DECIMAL types with precision higher than 10 are stored as DOUBLE PRECISION in dialect 1. Conversion to true, 64-bit fixed numeric types is not done when you change the dialect to 3—you must create new columns of the required type and cast the old values into the new columns.

Firebird inherited some features to assist with migrating from dialect 1 to Firebird’s native SQL dialect (known as dialect 3). It’s widely acknowledged that there are much easier and safer ways to do this migration. Best results are achieved by extracting a metadata script, updating it, if necessary, and reconstituting an “empty” dialect 3 database. Excellent free and low-cost data-pumping tools are widely available for repopulating your new database with your old data.

Database Backup and Restore Rights

Use of gbak is restricted to SYSDBA and the owner of the database named in the backup or restore request.

Changing Ownership of a Database

A restored database file, or one created from a gbak file, is owned by the user that performed the restore. Backing up and restoring a database is thus a mechanism for changing the ownership of a database.

User Name and Password

When Firebird checks authority to run gbak, it determines the user according to the following hierarchy:

  1. The user name and password specified as switches in the gbak command.
  2. For a local gbak only,2 the user name and password specified in the ISC _USER and ISC _PASSWORD environment variables, provided they also exist in the security database (security.fdb in v.1.5; isc4.gdb in v.1.0.x). Keeping these environment variables set permanently is strongly not recommended, since it is extremely insecure.
  3. For POSIX only, if no user credentials are supplied at either of the previous levels, Firebird allows the root user to run gbak from the server or from a trusted host.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Firebird Topics