Difference between revisions of "Recover corrupted family tree"

From Gramps
Jump to: navigation, search
(family tree recovery)
Line 1: Line 1:
 
{{languages}}
 
{{languages}}
Explaination of '''GRDB corruption''', how to recover from it, and how to avoid it in the future.
+
Explaination of '''family tree''' and '''GRDB corruption''', how to recover from it, and how to avoid it in the future.
  
==What causes this corruption?==
+
== Family Tree corruption ==
 +
=== What causes this corruption? ===
 +
Not really known. Database corruption with family trees is however far less likely than with the previous format of storing your family tree Gramps version 2.2.x uses
 +
 
 +
=== How do you know about it? ===
 +
 
 +
Gramps might give you on startup that recovery is needed via a dialog box:
 +
 
 +
GRAMPS has detected a problem in the underlying Berkeley database.
 +
This can be repaired by from the Family Tree Manager.
 +
Select the database and click on the Repair button
 +
 
 +
But it might happen no Repair button is present, or you obtain the error (visible in terminal)
 +
 
 +
(-30975, 'DB_RUNRECOVERY: Fatal error, run database recovery -- PANIC: Invalid argument').
 +
 
 +
=== What to do now? ===
 +
 
 +
It is advisable not to click the repair button right away. It should work, but GRAMPS might believe an error is present while this is in reality not true. Repairing your tree then will lead to loss of the last typed changes.
 +
 
 +
Instead, take a backup of the family tree that is given problems. In a terminal do:
 +
 
 +
gramps -l
 +
 
 +
This will give you a list with all family trees and the directory where they are stored, normally somewhere in the directory  ~/.gramps/grampsdb. Copy the directory of the tree with problems so as to have a backup:
 +
 +
cp <target directory> <backup directory>
 +
 
 +
If the recover button was present on the GRAMPS family tree, click it. All should work again. If you notice you lost information, or the repair button does not work, then do the following.
 +
If recovery worked, but you do not like the result, backup this data and place your backup taken above back in its original position. You now have again the bad family tree to work on. Next, obtain the bsddb recovery tools, see your distributions package search page. The program is called db4.6_recover, where 4.6 might be an older or newer version number.
 +
 
 +
Run this tool as follows:
 +
 
 +
cd /home/<user>/.gramps/grampsdb/<target directory>
 +
db4.6_recover -c
 +
 
 +
That should do the trick, and allow GRAMPS to load the family tree. If not, then start a ticket on the gramps bug tracker.
 +
 
 +
== Version 2.2.x: GRDB corruption ==
 +
===What causes this corruption?===
 
The leading cause of grdb corruption is moving the grdb file from its original location. Whether you move the file to another directory, rename it, copy into another file, transfer to another machine, or another user account -- all of those will "corrupt" the file.
 
The leading cause of grdb corruption is moving the grdb file from its original location. Whether you move the file to another directory, rename it, copy into another file, transfer to another machine, or another user account -- all of those will "corrupt" the file.
  
Line 13: Line 52:
 
Not being able to open a /tmp/... file in GRAMPS 3.0.x on opening grdb files indicates database corruption. This is because the grdb file you want to open is copied to the /tmp dir, and then opened. All failure results in the '/tmp/tmpxxxxx could not be opened'
 
Not being able to open a /tmp/... file in GRAMPS 3.0.x on opening grdb files indicates database corruption. This is because the grdb file you want to open is copied to the /tmp dir, and then opened. All failure results in the '/tmp/tmpxxxxx could not be opened'
  
==What do I do now?==
+
===What do I do now?===
 
The answer depends on whether or not you have the environment for that database. If you just copied one file into another then the environment may still work. If you modified the original database since then, the original environment has changed and there's no good environment for the new file. If you removed your <code>.gramps</code> directory (why oh why?) then all environments are lost. So act depending on the situation, as explained below.
 
The answer depends on whether or not you have the environment for that database. If you just copied one file into another then the environment may still work. If you modified the original database since then, the original environment has changed and there's no good environment for the new file. If you removed your <code>.gramps</code> directory (why oh why?) then all environments are lost. So act depending on the situation, as explained below.
  
===The environment still exists===
+
====The environment still exists====
 
If you have environment directory for that file, copy it under the above gudelines.
 
If you have environment directory for that file, copy it under the above gudelines.
 
;Example: You copied <code>/home/user/genealogy/MyData.grdb</code> to <code>/home/user/genealogy/backup/BackupData.grdb</code> and the new file is not working.
 
;Example: You copied <code>/home/user/genealogy/MyData.grdb</code> to <code>/home/user/genealogy/backup/BackupData.grdb</code> and the new file is not working.
 
;Solution: Copy <code>/home/user/.gramps/env/home/user/genealogy/MyData.grdb</code> directory into <code>/home/user/.gramps/env/home/user/genealogy/backup/BackupData.grdb</code> and this should fix the problem.
 
;Solution: Copy <code>/home/user/.gramps/env/home/user/genealogy/MyData.grdb</code> directory into <code>/home/user/.gramps/env/home/user/genealogy/backup/BackupData.grdb</code> and this should fix the problem.
  
===The environment is lost===
+
====The environment is lost====
 
If you don't have the original environment for that file, you may try dumping and loading your data using Berkeley DB tools. Depending on your system, they may be called <code>db_dump</code> and <code>db_load</code>, <code>db41_dump</code> and <code>db41_load</code>, <code>db4.4_dump</code> and <code>db4.4_load</code>, ... In Ubuntu you find them in the package <code>db4.4-util</code>. You might need more recent versions depending on the version your distribution uses in its python package. So for eg Ubuntu Hardy created files, you will need <code>db4.6-util</code>. Whatever they are called, there should be a dump tool and a load tool, and they should be version 4 or later.
 
If you don't have the original environment for that file, you may try dumping and loading your data using Berkeley DB tools. Depending on your system, they may be called <code>db_dump</code> and <code>db_load</code>, <code>db41_dump</code> and <code>db41_load</code>, <code>db4.4_dump</code> and <code>db4.4_load</code>, ... In Ubuntu you find them in the package <code>db4.4-util</code>. You might need more recent versions depending on the version your distribution uses in its python package. So for eg Ubuntu Hardy created files, you will need <code>db4.6-util</code>. Whatever they are called, there should be a dump tool and a load tool, and they should be version 4 or later.
  
Line 39: Line 78:
 
Note: If you downgrade your distribution, it might be needed to do dump with 4.6 tools, and load with 4.4 or 4.5 tools.
 
Note: If you downgrade your distribution, it might be needed to do dump with 4.6 tools, and load with 4.4 or 4.5 tools.
  
==How to prevent corruption?==
+
===How to prevent corruption?===
 
While moving the file is the leading cause of corruption, apparently there are other less frequent causes that we don't fully know. So preventing corruption is not always possible.
 
While moving the file is the leading cause of corruption, apparently there are other less frequent causes that we don't fully know. So preventing corruption is not always possible.
  
Line 50: Line 89:
 
Also, use XML format for any data migration. Moving to another machine, sending data to grandma, copying to another user on the same machine -- all of these cases should use XML.
 
Also, use XML format for any data migration. Moving to another machine, sending data to grandma, copying to another user on the same machine -- all of these cases should use XML.
  
==Can you guys not solve this ? ==
 
Starting with GRAMPS 3.0, this has been [[Database Formats#Family Tree Manager|completely reworked]] using the simpler [[Gramps 3.1 Wiki Manual - Manage Family Trees#Starting a New Family Tree|Family Tree Manager]].
 
 
But ''DB_RUNRECOVERY'' could still [http://www.gramps-project.org/bugs/view.php?id=2818 happend] !
 
If so, you may try :
 
 
gramps -l
 
To find <target directory> in ~/.gramps/grampsdb
 
 
cp <target directory> <backup directory>
 
To perserve the old
 
 
cd /home/<user>/.gramps/grampsdb/<target directory>
 
db4.6_recover -c
 
  
 
[[Category:How do I...]]
 
[[Category:How do I...]]

Revision as of 11:40, 4 July 2009

Explaination of family tree and GRDB corruption, how to recover from it, and how to avoid it in the future.

Family Tree corruption

What causes this corruption?

Not really known. Database corruption with family trees is however far less likely than with the previous format of storing your family tree Gramps version 2.2.x uses

How do you know about it?

Gramps might give you on startup that recovery is needed via a dialog box:

GRAMPS has detected a problem in the underlying Berkeley database.
This can be repaired by from the Family Tree Manager.
Select the database and click on the Repair button

But it might happen no Repair button is present, or you obtain the error (visible in terminal)

(-30975, 'DB_RUNRECOVERY: Fatal error, run database recovery -- PANIC: Invalid argument'). 

What to do now?

It is advisable not to click the repair button right away. It should work, but GRAMPS might believe an error is present while this is in reality not true. Repairing your tree then will lead to loss of the last typed changes.

Instead, take a backup of the family tree that is given problems. In a terminal do:

gramps -l 

This will give you a list with all family trees and the directory where they are stored, normally somewhere in the directory ~/.gramps/grampsdb. Copy the directory of the tree with problems so as to have a backup:

cp <target directory> <backup directory>

If the recover button was present on the GRAMPS family tree, click it. All should work again. If you notice you lost information, or the repair button does not work, then do the following. If recovery worked, but you do not like the result, backup this data and place your backup taken above back in its original position. You now have again the bad family tree to work on. Next, obtain the bsddb recovery tools, see your distributions package search page. The program is called db4.6_recover, where 4.6 might be an older or newer version number.

Run this tool as follows:

cd /home/<user>/.gramps/grampsdb/<target directory>
db4.6_recover -c

That should do the trick, and allow GRAMPS to load the family tree. If not, then start a ticket on the gramps bug tracker.

Version 2.2.x: GRDB corruption

What causes this corruption?

The leading cause of grdb corruption is moving the grdb file from its original location. Whether you move the file to another directory, rename it, copy into another file, transfer to another machine, or another user account -- all of those will "corrupt" the file.

What happens is that the grdb file needs its database environment -- a directory with log files, lock files, temp files, etc. The 2.2.x gramps releases uses grdb files and stores the environment for each file, under a tree in a ~/.gramps/env directory. If your grdb file is /home/user/genealogy/MyData.grdb then its environment is in the /home/user/.gramps/env/home/user/genealogy/MyData.grdb directory.

So moving, copying, or renaming the file will copy the file's bytes, but not its environment. This is why the moved file appears corrupted.

Another cause can be an upgrade or downgrade of your operating system to a bsddb database backend that does not support fully the previous form of the database (eg, changed hash versions). This will also seem like a corruption in GRAMPS, but actually means the bsddb tools must be used to convert to data to a new version.

Not being able to open a /tmp/... file in GRAMPS 3.0.x on opening grdb files indicates database corruption. This is because the grdb file you want to open is copied to the /tmp dir, and then opened. All failure results in the '/tmp/tmpxxxxx could not be opened'

What do I do now?

The answer depends on whether or not you have the environment for that database. If you just copied one file into another then the environment may still work. If you modified the original database since then, the original environment has changed and there's no good environment for the new file. If you removed your .gramps directory (why oh why?) then all environments are lost. So act depending on the situation, as explained below.

The environment still exists

If you have environment directory for that file, copy it under the above gudelines.

Example
You copied /home/user/genealogy/MyData.grdb to /home/user/genealogy/backup/BackupData.grdb and the new file is not working.
Solution
Copy /home/user/.gramps/env/home/user/genealogy/MyData.grdb directory into /home/user/.gramps/env/home/user/genealogy/backup/BackupData.grdb and this should fix the problem.

The environment is lost

If you don't have the original environment for that file, you may try dumping and loading your data using Berkeley DB tools. Depending on your system, they may be called db_dump and db_load, db41_dump and db41_load, db4.4_dump and db4.4_load, ... In Ubuntu you find them in the package db4.4-util. You might need more recent versions depending on the version your distribution uses in its python package. So for eg Ubuntu Hardy created files, you will need db4.6-util. Whatever they are called, there should be a dump tool and a load tool, and they should be version 4 or later.

Basically, you just dump the grdb into a text file, then create a new grdb from that text file:

   $ db4.4_dump BackupData.grdb > somefile.txt
   $ db4.4_load newfile.grdb < somefile.txt

and then cross your heart and hope that newfile.grdb will open in GRAMPS.

If you obtain the error:

db4.4_dump: eidtrans: unsupported hash version: 9

this is an indication you need a more recent version. So use db4.6 tools:

   $ db4.6_dump BackupData.grdb > somefile.txt
   $ db4.6_load newfile.grdb < somefile.txt

Note: If you downgrade your distribution, it might be needed to do dump with 4.6 tools, and load with 4.4 or 4.5 tools.

How to prevent corruption?

While moving the file is the leading cause of corruption, apparently there are other less frequent causes that we don't fully know. So preventing corruption is not always possible.

What is possible though is to backup the data regularly. The backups should be in XML format (the .gramps format). XML is machine- and human-readable. It is completely self-sufficient. It is also small. The following are good practices of backups:

  1. Export to XML from time to time, especially after large edits.
  2. Export to XML before making big changes, such as importing new data into an existing database from e.g. GEDCOM, merging records, running tools that may heavily modify the data, etc.
  3. Export to XML before upgrading GRAMPS to a newer version. Apparently, export to XML with old version before you install the new one!
  4. Export to XML before upgrading your OS.

Also, use XML format for any data migration. Moving to another machine, sending data to grandma, copying to another user on the same machine -- all of these cases should use XML.