Search code examples
backupfirebirdrestore

How to backup/restore a Firebird database?


I am really confused here about Firebird v2.5 backup/restore process. What should I use to backup/restore a local Firebird database: fbsvcmgr.exe, gbak.exe, isql.exe or nbackup.exe

Are these all options or I am wrong about something!

What is the practical way to do it for a C++ application?

How should I know if a database already exists the first time, so I can decide whether to restore it or not.


Solution

  • There are two primary ways to create backups in Firebird:

    • gbak, which creates a logical backup of the database (object 'descriptions' (e.g. table structure, views, etc) and data)
    • nbackup (also known as nbak), which creates a physical backup of the database (physical data pages changed since the previous nbackup)

    In most cases, I'd suggest to use gbak, because it is simpler and also allows you to move backups between platforms and Firebird versions, while nbackup is only really suitable for the same platform and Firebird version (but has the advantage of allowing incremental backups).

    ISQL is an interactive query CLI, and cannot be used to create backups. Fbsvcmgr is the "Firebird Service Manager" tool, which can be used to invoke service operations on a (remote) Firebird server. This includes backup and restore operations through gbak and nbackup. Fbsvcmgr is pretty low-level and hard to use (see fbsvcmgr -? for options).

    For gbak, you'd normally invoke the services through the gbak executable (option -se[rvice] <service>), see also Remote Backups & Restores in the gbak documentation. For nbackup you either can use the nbackup tool locally, or you need to use the fbsvcmgr (or another tool that supports service operations) to invoke the same functionality remotely (action_nbak and action_nrest), see also Backups on remote machines (Firebird 2.5+) in the nbackup documentation.

    For detailed description on gbak, see gbak - Firebird Backup & Restore Utility. For nbackup, see Firebird's nbackup tool.

    With a gbak backup, you'd normally restore the database using 'create' (option -c[reate]) or 'recreate' (-r[ecreate] without o[verwrite] option), which will fail if the database file already exists. See also the gbak manual linked above for more information.

    I won't really answer your question about how to do it from a C++ application, because I don't program C++, and your question is already too broad as it is. But know that it is possible to invoke Firebird service operations, including backup and restore using both gbak and nbackup, from C++ code (that is essentially what Firebird tools itself do). If you want to know more about that, I'd suggest you ask on the firebird-support Google Group.