As far as I know, the only way is to query the RDB$BACKUP_HISTORY (there is no call to the service manager for this). To get the latest backup, you can use:
SELECT RDB$BACKUP_ID, RDB$TIMESTAMP, RDB$BACKUP_LEVEL, RDB$GUID, RDB$SCN, RDB$FILE_NAME FROM RDB$BACKUP_HISTORY ORDER BY RDB$TIMESTAMP DESC ROWS 1
The RDB$BACKUP_HISTORY has the following columns:
RDB$BACKUP_ID primary keyRDB$TIMESTAMP backup timestampRDB$BACKUP_LEVEL support levelRDB$GUID guid for backup (this is also used in backup files for monitoring and dependency checking)RDB$SCN highest page marker in the backup (see below)RDB$FILE_NAME backup file name
Nbackup physically backs up database pages. SCN (short for page crawl ...) is the number that is used to mark database pages. This number increases with every change in the state of the backup, for each backup with nbackup there are 3 state changes: nbak_state_normal (without backup) → nbak_state_stalled (the database writes to the delta file) → nbak_state_merge (merging the delta file back to the database) → nbak_state_normal (no backup).
The first backup gets SCN 0, the second SCN 3, etc. (no matter what level).
- SCN 0: Pages before any backup
- SCN 1: pages written / updated to delta file during backup
- SCN 2: pages written / updated during the merge of the delta file into the main backup (although I'm not sure if the pages from the delta file written back to the main file receive SCN 1 or 2)
- SCN 3: pages written / updated after the completion of the first backup + merge
- ...
- SCN 6: pages written / updated after the end of the second backup + merge
When you create a level 1 backup, it searches for a backup of the last level 0 and backs up all pages with an SCN higher than the SCN of a level 0 backup (etc.). This is also described in the Firebird 2.1 Release Notes: New Incremental Online Backup .
Note that backing up and restoring with gbak will clear the RDB$BACKUP_HISTORY and reset the SCN of all pages to 0. The reason for this is that gbak creates a logical backup instead of a physical backup. Thus, gbak recovery will overwrite the entire database (and may even change the page size). This makes previous backups with nbackup pointless as a starting point for subsequent backups: you need to start at a new level of 0.
Since this information is not in the nbackup manual, I created a ticket for the Firebird tracker: http://tracker.firebirdsql.org/browse/DOC-94
Mark rotteveel
source share