Database file saved at each database update

Experience showed that "save at exit" is not reliable enough.
Sometimes the database wasn't saved, losing session settings.
Sometimes the sotrage process stopped in the middle, breaking the whole
database for the next load.

I assume this is due to shutdown races.
Fix has two parts:
* save at each database update.
* during storing process, write to a temporary file and rename it on
success (added reliability)