DB image malformed. How to fix it?

Thanks, saved my logs after a restore as well. This took about 3-5 minutes on a Raspberry Pi 4 with a 1GB Sqlite DB. Resulting DB was 22 MB, so I guess it threw a lot of corrupted data out.

For those struggling with the “install sqlite3 in the homeassistant container” - no need on Hass.io (or whatever it’s being called now.)

If you enable the root login (don’t bother with the SSH addon, it doesn’t get you access to the low level OS the way the real root login does), you can do the fixes from the main shell of the system.

The config directory is available in /mnt/data/supervisor/homeassistant

See https://developers.home-assistant.io/docs/operating-system/debugging#ssh-access-to-the-host for instructions on how to enable SSH root logins.

On a recent release, here’s how I did the recovery.

Prerequisites:

Enable SSH access to the host per procedure linked above.

Step 1: Login to the host

ssh -l root -p 22222 hassio

It will bring up the hassio-cli interpreter.

Step 2: Stop Hassio

Type core stop and wait for it to complete.

Step 3: Change directories to the data dir

  • Type login to get the root prompt.
  • Then, run
    cd /mnt/data/supervisor/homeassistant/

Step 4: Recover the SQLite database

Run the following, then grab a cup of coffee/tea/beer.

sqlite3 ./home-assistant_v2.db ".dump" | sqlite3 ./home-assistant_v2.db.fix
mv ./home-assistant_v2.db ./home-assistant_v2.db.broken
mv ./home-assistant_v2.db.fix ./home-assistant_v2.db

Step 5: Get back into the hassio-cli
Type hassio-cli to re-enter the interpreter

Step 6: Restart Home Assistant

core start

Validation:

Exit out of the hassio-cli by typing exit, then watch the homeassistant container’s logs:

docker logs --follow homeassistant
9 Likes