FirebirdSQL logo
A word on the inner workings
Note
What follows here is not necessary knowledge to use nbackup. It just gives a rough (and incomplete) impression of what happens under the hood during execution of nbackup -BACKUP:
  1. First of all, the main database file is locked by changing an internal state flag.From this moment on, any and all mutations in the database are written to a temporary file — the difference file or delta file.By default, the delta file is created in the same folder as a database file, with the additional extension .delta, for example: MyDatabase.fdb.delta

  2. Then the actual backup is made.This isn’t a straight file copy;restoring must be done by nbackup as well.

  3. Upon completion of the backup, the contents of the delta file are integrated with the main database file.After that, the database is unlocked (flag goes back to “normal”) and the delta is removed.

The functionality of steps 1 and 3 is provided by two new SQL statements: ALTER DATABASE BEGIN BACKUP and ALTER DATABASE END BACKUP.Contrary to what the names suggest, these statements do not take care of making the actual backup;rather, they create the conditions under which the main database file can be safely backed up.And to be clear: you don’t need to issue these commands yourself;nbackup will do that for you, at the right moments.

Restoring a full backup

A full backup is restored as follows:

nbackup -RESTORE database [backupfile]

For instance:

C:\Data> nbackup -RESTORE inventory.fdb inventory_1-Mar-2006.nbk
Comments
  • You don’t specify a level for a restore.

  • When restoring, the -RESTORE parameter must come last, for reasons that will become clear later.

  • Instead of a database filename you may also use an alias.

  • If the specified database file already exists, the restore fails, and you get an error message.

  • Here too, you may omit the name of the backup file.If you do, nbackup will prompt you for it.(Attention! In Firebird 2.0.0 this “interactive restore” feature is broken, leaving you with an error message and a failed restore. Fixed in 2.0.1.)

  • Restoring works purely on the filesystem level and can even be done without a Firebird server running.Any credentials supplied via the -USER and -PASSWORD parameters are ignored.The same goes for passwords read from a file.However, nbackup does try to read the password from the file if the -FETCH_PASSWORD parameter is present, and if an error occurs, the entire operation is abandoned.

Incremental backups

Warning

The incremental backup facility was entirely broken in Firebird 2.1.0, and fixed again in 2.1.1.

Making incremental backups

To make an incremental (“differential”) backup, specify a backup level greater than 0.An incremental backup of level N always contains the database mutations since the most recent level N-1 backup.

Examples:

One day after the full backup (level 0), you make one with level 1:

C:\Data> nbackup -BACKUP 1 inventory.fdb inventory_2-Mar-2006.nbk

This backup will only contain the mutations of the last day.

One day later again, you make another one with level 1:

C:\Data> nbackup -BACKUP 1 inventory.fdb inventory_3-Mar-2006.nbk

This one contains the mutations of the last two days, since the full backup, not only those since the previous level-1 backup.

Note

The previous incremental backup of any level must be completed before the start of the next incremental backup, otherwise nbackup execution will not do the desired backup, and return error "Database is already in the physical backup mode".

A couple of hours on we go for a level-2 backup:

C:\Data> nbackup -BACKUP 2 inventory.fdb inventory_3-Mar-2006_2.nbk

This youngest backup only contains the mutations since the most recent level-1 backup, that is: of the last few hours.