Power down and database corrupt

I had power down in my house and HA history is not longer visible. All history data as well as costs are gone. Database is corrupted and I have this file:
home-assistant_v2.db.corrupt.2023-01-17T19_12_01.938720+00_00

which shows exact time and date when power was down.

Can I somehow restore database from that file?
I am running HA on NUC with Win10 on virtual machine.
Thank you in advance.

Search the forum for “repair database” it will return results like this:

Thank you but I am not finding how to reuse and restore DB from home-assistant_v2.db.corrupt.2023-01-17T19_12_01.938720+00_00 file? What is the purpose of this file?

This file actually IS your database.

Perform the integrity checks listed in the linked topic. If fine (I don’t think so), you can power down HA and rename that file/database so it will be used by HA once you power it up again. You probably need to repair it first to make it usable again.

Everything should be said as many others experienced what you did, unfortunately.

Yessssss… I did it. I managed to fix corrupted DB.
How?
First I transferred corrupted DB to my Windows PC. Then I needed to install Sqlite3 application and run it from Windows 10 CMD.
In Sqlite3 command prompt I tried to use commands:

  1. .open home-assistant_v2.db
  2. .recover
  3. .save home-assistant_v2.db.fix

It didn’t work. When I load fixed/recovered home-assistant_v2.db into Home Assistant, there was again error that DB is corrupted and HA created new home-assistant_v2.db starting from scratch.

What helped is running this command line from Sqlite installation folder in Win10 CMD:
sqlite3 ./home-assistant_v2.db “.recover” | sqlite3 ./home-assistant_v2.db.fix

Can someone explain why opening, recovering and saving didn’t work but this CMD line with | worked?

Hello. I know topic is very old but problem i experience is this same. I did run pragma integrity_check on my corrupted file and somehow results come back as OK. So rename it and after reset problem persist. What else I can do to fix issue. Regards