Search code examples
backupfirebird

Firebird nbackup vs copy/paste


I am currently using Firebird 2.1

I found that it is possible to do a backup of a firebird database using nbackup.
nbackup will lock the DB when starting the copy and unlock it when restoring as described here .

However I also found out that is is possible to lock/unlock manually and also copy the DB using the copy/paste of the OS :

  • alter database begin backup;
  • then copy the DB file using standard file copy of the OS
  • alter database end backup;

What is the difference between these two methods? Is the second method as safe as the first one?

I want to add that I need to do the backup on a DB already in use by another program.


Solution

  • Locking the database with alter database begin backup;, copying the file, and then using alter database end backup; is just as safe as using nbackup, and this is also documented as one of the use cases of begin/end backup. During the backup state, the database file is not changed (the changes are instead made in the delta file, and are merged back into the database file when you end the backup mode).

    However, the important difference with nbackup is that nbackup allows you to do an incremental backup (and an incremental restore). This is possible because nbackup tracks the previous backups done, and allows you to only backup the database pages that were modified since the previous backup of a higher level.

    That is, a level-0 backup backs up the entire database. A level-1 backup only those database pages changed since the last level-0 backup, a level-2 backup the pages changed since the last level-1, and so on.

    For example, you do a weekly level-0 backup, daily level-1 backup and an hourly level-2 backup, then you can restore a database to the last hour by restoring the most recent level 0, 1 and 2 backups.

    For more information, read the nbackup manual. Keep in mind, that nbackup performs a physical backup of the database pages. Firebird also has the gbak tool to perform a logical database. Physical backups with nbackup can only be moved between the same Firebird version on the same CPU architecture and OS, while logical backups with gbak can be moved between Firebird versions, CPU architecture and OS.

    As an aside, and not related to your question, Firebird 2.1 has been end-of-life since December 2014. It is really high time to upgrade to a supported version (Firebird 3.0 or higher).