Using External Tools
Gbak
and nbackup
are the best tools to use when backing up and/or restoring Firebird databases.They have been extensively tested and know the internals of the database and how it works, so the chances of these tools corrupting your valuable data are very slim.However, some DBAs still like to use external tools (those not supplied with Firebird) to make backups for whatever reason.
Because it is not possible for external tools to know where a database is to be found, given the alias name, the scriptwriter and/or DBA must explicitly find out the correct location of the database file(s) and supply these to the external tool.To make this simpler for scriptwriters, my own installation uses a standard in my aliases.conf
file as follows:
-
The database alias must start in column one.
-
There must be a single space before the equals sign (=).
-
There must be a single space after the equals sign (=).
-
Double quotes around the database filename is not permitted — it doesn’t work for the Firebird utilities either.
-
Databases are all single file databases.
The last rule applies to my installation only and means that the following simple backup script will work.If multiple file databases were used, more coding would be required to take a backup using external tools.
tux> cat /opt/firebird/aliases.conf # --------------------------------------------------------- # WARNING: Backup Standards require that: # The database name starts in column 1. # There is a single space before the equals sign. # There is a single space after the equals sign. # The path has no double quotes (they don't work!) # ---------------------------------------------------------- employee = /opt/firebird/examples/empbuild/employee.fdb
The following shows the use of the gzip
utility on a Linux server to take and compress a backup of a running database.The following is run as the root user due to the requirement to run gfix
to shut down the database.
tux> # Backup the production employee database using gzip. tux> gfix -shut -tran 60 employee tux> DBFILE=`grep -i "^employee =" /opt/firebird/aliases.conf | cut -d" " -f3` tux> gzip -9 --stdout $DBFILE > /backups/employee.fdb.gz
The restore process for this database would be the reverse of the above.Again, the following runs as root.
tux> # Restore the production employee database from a gzip backup. tux> gfix -shut -tran 60 employee tux> DBFILE=`grep -i "^employee =" /opt/firebird/aliases.conf | cut -d" " -f3` tux> gunzip --stdout /backups/employee.fdb.gz > $DBFILE tux> # Make sure firebird can see the file. tux> chown firebird:firebird $DBFILE