I just had my laptop freeze and had to hard reboot.
When it came back both the blockchain and addr databases were corrupted and failed to load.
I had to restore an old backup to get bitcoin to run again.
Is it possible to somehow keep the database files consistent even in the event of a power failure or OS lockup?
We're only as good as BDB; see here: http://pybsddb.sourceforge.net/ref/transapp/reclimit.html
"it is important to select hardware that does not do partial writes and does not cache data writes (or does not return that the data has been written to stable storage until it has either been written to stable storage or the actual writing of all of the data is guaranteed, barring catastrophic hardware failure -- that is, your disk drive exploding). You should also be aware that Berkeley DB does not protect against all cases of stable storage hardware failure, nor does it protect against hardware misbehavior."
I think the real problem is that in the end, bdb doesn't seem appropriate for end-user desktop systems...
Perhaps something like 'backupwallet ' but for all data files would be useful. I could write a crontab to copy the .bitcoin folder in the early hours of each morning, but there's no guarantee that the files I copy are in a consistent state.
'backupdata " could copy all 4 .dat files to the specified backup directory, for instance.
Also, when a database file does become corrupted, the output in the terminal is very unhelpful. It doesn't indicate which of the files is corrupted (although scanning back up through the log can show which file was being read at the time) and offers the user no advice on how to proceed.
Closing this; automatic recovery is somewhat better now.