Detect that a base has been restored from a backup

18 views
Skip to first unread message

Pierre Y.

unread,
Nov 24, 2021, 4:19:28 AM11/24/21
to firebird...@googlegroups.com
Hello,

How can I detect at runtime that a database has been restored from a backup ? Are there internal counters or metadata in the database that may help ?

Thanks for your help, regards,

--
Pierre Yager
Crisalid

Mark Rotteveel

unread,
Nov 24, 2021, 4:41:43 AM11/24/21
to firebird...@googlegroups.com
On 24-11-2021 10:19, Pierre Y. wrote:
> How can I detect at runtime that a database has been restored from a
> backup ? Are there internal counters or metadata in the database that
> may help ?

When gbak is used, the header page of the database will have an updated
creation date with the date of the restore. You can use also the
transaction counters (reset to a lower value) or the database GUID
(different GUID) as an indication.

With nbackup, the creation date and transaction counters are not reset.
However, the database GUID will normally change after restore (unless
the FB4+ -sequence option is used).

Mark
--
Mark Rotteveel

Pierre Y.

unread,
Nov 24, 2021, 5:00:51 AM11/24/21
to firebird...@googlegroups.com
Thank you Mark.

I just checked that the date got using isc_info_creation_date is not updated after a restore. It remains the same.

And, do you know how I can retrieve the database GUID (using the Firebird API) ?

I'm investigating the NextTransaction number. Even if someone restores a copy of a somewhat older FDB, without restoring a backup, I could detect that with the NextTransaction number.


--
You received this message because you are subscribed to the Google Groups "firebird-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebird-suppo...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/firebird-support/9f1a405b-86f4-fdc4-2517-9e866b059917%40lawinegevaar.nl.

Mark Rotteveel

unread,
Nov 24, 2021, 5:11:35 AM11/24/21
to firebird...@googlegroups.com
On 24-11-2021 11:00, Pierre Y. wrote:
> I just checked that the date got using isc_info_creation_date is not
> updated after a restore. It remains the same.

I checked with Firebird 4.0, and there Creation date on the header page
(gstat -h) is updated (and I assume that is the value reported by
isc_info_creation_date, but I don't have time to verify that right now).

> And, do you know how I can retrieve the database GUID (using the
> Firebird API) ?

You can retrieve it with fb_info_db_guid (= 144)

> I'm investigating the NextTransaction number. Even if someone restores a
> copy of a somewhat older FDB, without restoring a backup, I could detect
> that with the NextTransaction number.

You could also use the Next Attachment ID from the header page as an
indicator, but I believe that one roles over.

Mark
--
Mark Rotteveel

Pierre Y.

unread,
Nov 24, 2021, 5:24:15 AM11/24/21
to firebird...@googlegroups.com
Mark,

Thank you again.

I'm still using Firebird 3.0.8

It looks like it does not provide the fb_info_db_guid info string.

There is a fb_info_db_file_id (145) but as far as I understand it provides a system level unique id for the file currently opened so it may not be the same each time the database is opened.

Regards,

--
Pierre

--
You received this message because you are subscribed to the Google Groups "firebird-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebird-suppo...@googlegroups.com.

Mark Rotteveel

unread,
Nov 24, 2021, 5:31:53 AM11/24/21
to firebird...@googlegroups.com
On 24-11-2021 11:24, Pierre Y. wrote:
> Mark,
>
> Thank you again.
>
> I'm still using Firebird 3.0.8
>
> It looks like it does not provide the fb_info_db_guid info string.
>
> There is a fb_info_db_file_id (145) but as far as I understand it
> provides a system level unique id for the file currently opened so it
> may not be the same each time the database is opened.

It looks like the database GUID is only set in FB 3.0 when nbackup has
been used, and Firebird 4.0 will set it always (probably because it is
also used in replication scenarios).

Mark
--
Mark Rotteveel

Pierre Y.

unread,
Nov 25, 2021, 5:27:39 AM11/25/21
to firebird...@googlegroups.com
Hi Mark,

My bad. I didn't checked the creation date of the right database. I can confirm that, even in Firebird 3.0.8, the database creation date is updated by restoring a database.

Thank you for your help,

--
Pierre

--
You received this message because you are subscribed to the Google Groups "firebird-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebird-suppo...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages