Mark
Mark

Reputation: 812

Copy a live Firebird .fdb database

I want to make a copy of a live Firebird .fdb database. I understand that simply copying it could result in a corrupted database and I looked into using the gbak command because it is able to perform a backup while the database is running.

So that will give me a database backup but I would need to restore this before I can use it. My database is nearly 1GB and takes 10 minutes to restore which is too long. Is there any other method to simply copy a Firebird live database from one location to another safely?

So far I have used the following to backup (which works):

gbak -v -t -user SYSDBA -password "masterkey" 127.0.0.1:"C:/Files/Live/Database.fdb" "C:\Test\Test.fbk"

I also tried using the following to backup and restore at the same time:

gbak -c [options] <source database> stdout | gbak -r [options] stdin <target database>

but this kept giving the error:

Done with volume #1, "new.gbak"
Press return to reopen that file, or type a new
name followed by return to open a different file. 

Upvotes: 3

Views: 5985

Answers (2)

Mark Rotteveel
Mark Rotteveel

Reputation: 108941

The risk of corruption is due to the way Firebird writes it file. Your copy might contain inconsistent data when copied at the same time that Firebird (re)writes a datapage. As far as I know the only real risk of corruption is during writes of index pages (and then only for index page splits), otherwise it just leads to inconsistent data and dangling transactions (which wouldn't be visible anyway as the transaction is not committed).

If you really don't want to use a backup, you can set the Firebird database in a backup state. This freezes the database and writes the changes to a delta file instead. You enable this state using ALTER DATABASE BEGIN BACKUP and end this state using ALTER DATABASE END BACKUP. See the documentation for ALTER DATABASE. This command was added in Firebird 2.0. You will need to "fixup" the copy of the database to make it workable. This can be done with nbackup -fixup (or -f) option

For the second part of your question (which really should have been posted as a separate question):

The command gbak -c doesn't create a backup, it creates a database from a backup (it is the brother of -r o/-recreate_database overwrite and -rep/-replace_database, but doesn't overwrite an existing database). See Restore Switches for more information.

See Create a Database Clone Without a Dump File for an example of how you can make a backup like this:

gbak -backup emptest stdout | gbak -replace stdin emptest_2

Upvotes: 6

cincura.net
cincura.net

Reputation: 4150

You can do

alter database begin backup;

then copy the file using standard file copy of your OS and

alter database end backup;

Also I strongly recommend reading these pages [1] [2] about nbackup.

Upvotes: 4

Related Questions