Firebird Database Backup
and Restore Using GBAK
GBAK is Firebird's command line tool for
online backup and restore of a complete database.
General Syntax
gbak <options> -user <username> -password <password> <source> <destination>
Backup
For backups, <source> is the database you
want to back up, <destination> is the file name of the
backup file. The usual extension is .fbk for Firebird and .gbk
for InterBase.
Only SYSDBA or the database owner can
perform a backup. For multi-file databases, specify only the
name of the first file as the database name.
Restore
For restores, <source> is the backup file
and <destination> is the name of the database that is to be
built up from the backup file. You will have to specify the
-C option for restore.
General Options
-pa[ssword] <password>
|
Database password |
-role <role>
|
Connect as role |
-se[rvice]
<hostname>:service_mgr
|
Backup: Creates the backup file
on the database server, using the Service Manager.
Restore: Creates the database from a backup file on
the server, using the Service Manager. |
-u[ser] <username>
|
Database user name |
-v[erbose]
|
Verbose output of what GBAK is
doing |
-y <filename>
|
Redirect all output messages to
<filename>
The file must not exist before running GBAK! |
-y suppress_output
|
Quiet mode |
-z
|
Show GBAK version and server
version |
Backup Options
-b[ackup_database]
|
Back up. This switch is optional. |
-co[nvert]
|
Converts external tables to
internal tables |
-e[xpand]
|
Creates an uncompressed backup |
-fa[ctor] n
|
Blocking factor for tape device |
-g[arbage collect]
|
Does not perform garbage
collection (sweeping) during backup |
-ig[nore]
|
Ignores checksum errors while
backing up |
-l[imbo]
|
Ignores limbo transactions while
backing up |
-m[etadata]
|
Only backs up metadata (schema).
No table data will be stored. |
-nt
|
Non-transportable format (use
only when you know you will restore on same platform
and database version) |
-t[ransportable]
|
Creates a transportable backup
(transportable between platforms and server
versions) |
Restore Options
-bu[ffers]
|
Set cache size for restored
database |
-c[reate_database]
|
Restore (mandatory) |
-i[nactive]
|
All indexes will be restored as
INACTIVE |
-k[ill]
|
Does not create shadows that are
defined in the backup |
-mo[de] read_write
|
Restores to a read/write database
(This is the default) |
-mo[de] read_only
|
Restores to a
read-only database |
-n[o_validity]
|
Does not restore validity
constraints. So you can restore data that does not
meet these constraints and could not be restored
otherwise. |
-o[ne_at_a_time]
|
Restores one table at a time. You
can use this to partially restore databases with
corrupt table data |
-p[age_size] <size>
|
Sets page size of new database.
<size> can be one of 1024, 2048, 4096, 8192. Default
is 1024. |
-r[eplace_database]
|
Restores over an existing
database. This can only be performed by SYSDBA or
the owner of the database that is overwritten. Do
NOT restore over a database that is in use! |
-use_[all_space]
|
Normally, on restore, database
pages will be filled to about 80 %. With the
use_all_space option, database pages will be filled
to 100 %. (Useful for read-only databases which will
see no more modifications) |
Examples
In all
examples -user, -role and -password options are omited for
clar-ity. In a real world situation they (or their
corresponding envirom-nemt variables) should be used.
Note that filename
extensions used here are just recommended. Using
unified extensions scheme helps guess file type just by
looking at its extension.
Here are some commonly used extensions:
.fdb Firebird
database
.gdb Firebird
database, legacy extension from the days when Fire-
bird was Interbase. gdb actually comes from Grotton
database,
named after the company that created the software back in
???
FIXME
.fdb.2 Second file of
multi-file database
.fdb.3 Third file of
multi-file database
.fdb.N N-th file of
multi-file database
.fbk Firebird
backup file
.gbk Legacy
extension for backup file
.fbk.gz Gzipped backup file
Backup a database into a compressed
format
gbak -b db-srv://database.fdb /dev/stdout | gzip > /file.fbk.gz
Restore a database into new filename
zcat /file.fbk.gz | gbak -c /dev/stdin db-srv://new-database.fdb
Multi-file backups
Syntax for backup
gbak [options]
<database> <target file 1> <size 1> <target file 2> <size 2>
... <target file n>
NOTE: Do not specify a size for the last
file. It will always be filled to take up what is left over,
no matter how large.
Size can be given in bytes (8192),
kilobytes (1024k), megabytes (5m), or gigabytes (2g)
Syntax for restore
gbak -c [options]
<source file 1> <source file 2> ... <source file n>
<database>
Restoring to a multi-file
database
gbak -c [options]
<source file> <db file 1> <size 1> <db file 2> <size 2> ...
<db file n>
NOTE: Do not specify a size for the last
database file. It can always grow unlimited to take up the
rest.
Size can be given in bytes (8192),
kilobytes (1024k), megabytes (5m), or gigabytes (2g)
Restoring from a
multi-file backup to a multi-file database
gbak -c [options]
<source file 1> <source file 2> ... <source file n>
<db file 1> <size 1> <db file 2> <size 2> ... <db file n>
If you want more options
and how to use gbak check gbak
man page