24 Steps To Become Firebird Backup Master

Firebird backup tool gbak is the powerful command-line tool. In this article, we will go step-by-step through the most popular backup and restore options of gbak.

What is gbak?

Gbak is a standard Firebird command-line tool (see its official documentation here), designed to perform a full backup of the database: it reads every record in the database and stores them to the backup file.
For developers and administrators with experience with other RDBMS, the term “backup” could be a bit confusing, since gbak produces not the exact copy of the database, but the file in the non-database format, only with data (indices are stored as declarations).
To create a database from the gbak backup file, the restore process with gbak should be performed.

1. Mastering Backups with Gbak

1.0. Preparation

Let’s create folder C:\data and put there copy of the Firebird example database employee.fdb. Employee.fdb is located in the \examples\empbuild subfolder of Firebird installation.
For Linux users – let’s create folder /db and change it owner to firebird, and copy employee.fdb there (from /opt/firebird/examples/empbuild)
mkdir /db
chown firebird -R /db
To measure the performance of various types of commands, we will use a small 5Gb database, generated from the Firebird OLTP-EMUL test, with some garbage versions inside (see statistics).

1.1 The simplest (but not the best) Firebird backup with gbak command

Windows gbak -b c:\Data\employee.fdb C:\data\backup1.fbk -user SYSDBA -pass masterkey Linux gbak -b /db/employee.fdb /db/backup1.fbk -user SYSDBA -pass masterkey In this example, gbak tool accesses database file using local or embedded access. Embedded access in the default configuration for Firebird 3.0 (with parameter in firebird.conf ServerMode = SuperServer) will try to put exclusive lock on the database, so other connections will be unable to access the database (or gbak attempt will fail due to the active connections). With Firebird 2.5 the command will work fine through XNET (if you have the only Firebird instance running, of course). This command runs under user permissions of the console you started. Normally, Firebird service on Windows runs with LocalSystem account, and on Linux under user “firebird”, but your console is usually your own user account or Administrator. If a user account of console does not have access to the database path or backup path, the gbak will fail with error “Cannot open backup file” (see example in Application 1. Errors, #5). Note: gbak -b silently overwrites the backup file. So, if you already have backup1.fbk, it will be overwritten. Time to backup for this command: 176 seconds