Even if we take great care, it may happen that a Firebird DB may be corrupted.
Here you can find a list of corruptions reasons.
In this post I describe a brief guide of how to repair a corrupt database using the command line tools (gfix and gbak).
NB: Please note that not all the corrupted database can be restored. It depends on the corruption level. At the end of this tutorial you can find some rescue alternatives.
Step 1: Check the database integrity
First of all you should stop the Firebird server and make a copy of the database files. Keep these files in a secure place until you are sure that the database is perfectly restored!
You can use the following command to check the db integrity:
gfix -v -f -user sysdba -password masterkey db_corrupt.gdb params: -v -> validate -f -> full
This command will print a summary of validation errors.
Step 2: Fix the errors
Use the following command to mend the db:
gfix -mend -user sysdba -password masterkey db_corrupt.gdb
Note that this command do not fix the errors, but flags the problems to be fixed. The errors will be solved in the next backup/restore step.
Step 3: Backup the DB
Use the following command to backup the db:
gbak -b -v -ig -user sysdba -password masterkey db_corrupt.gdb db_corrupt.gbk params: -b -> backup -v -> verbose -ig -> ignore checksums
Step 4: Restore the DB
Use the following command to restore the db:
gbak -c -v -user sysdba -password masterkey db_corrupt.gbk db_fixed.gdb params: -c -> create new db -v -> verbose
Step 5: Re-check the DB
Repeat the command in step 1 to check the new db:
gfix -v -f -user sysdba -password masterkey db_fixed.gdb
Possible alternatives:
-
If the database has still problems you can try to repeat the procedure using
-g
options (switch off garbage collection) in step 3.
So step 3 will be:gbak -b -v -ig -g -user sysdba -password masterkey db_corrupt.gdb db_corrupt.gbk
- If the database has still problems you can try to use a tool like IBSurgeon Tools (but I have never used them!)
- If the db is corrupted but you can access to the data, you can copy the data to a new db using FbCopy or IB-Pump.
Related Links:
How to repair a corrupt Firebird database (The Firebird FAQ)
How To Analyse and Repair a Corrupted Database (IBPhoenix)
How to repair a corrupt Firebird database? (IBSurgeon)
Comments on: "How to repair a corrupted Firebird database" (1)
Thank you. This is very helpfull.