My install of HA corrupted it’s self. I left work six hours early after I discovered HA wasn’t responding and have been trying to recover for the past 8 hours now to no avail. I can get it to boot as far as waiting for CLI in the console, but then I get " Home Assistant CLI not starting! Jump into emergency console" I have tried to get past this several times by typing login but it just comes back to that."
I have a recent backup(with in a day actually) but apparently it doesn’t include any of the history stats. I don’t care much for any of that since it all purges after two weeks anyways but I’ve lost almost two years of energy data. That is what I would like to recover. It is installed as a VM on a qnap nas.
without knowing how was your system setup it is hard to say - but if you are able to read your hard drive/sd card/virtual disk/etc then when you restore your backup you should be able to copy the HA database of that file (home-assistant_v2.db file in the config directory)
The energy data and statistics are stored in the same database than other HA data: events, short term statistics… So if you have access to your short term data you should be able to access your long term data as well (except if the data was already corrupted at the time of the backup)…
I would do what @alfwro13 is recommending : reinstall from scratch and restore the backup done with HA but before doing that, I would do a full backup of your environment (HA virtual machine) if possible… so if some one as a better/different idea, you could maybe restore the VM and restart from there…
I am not familiar with that but spin up a linux box i.e. ubuntu and when that is running try mounting your corrupted HA virtual drive to that box - https://www.qnap.com/en/how-to/tutorial/article/how-to-use-virtualization-station-3 - on picture 4 on that page I see that there is an option to use existing image (next to where it says HDD Location) - that screen shot is for creating VMs but I suspect it will be the same (or similar) when editing existing systems
Now I can’t get a new VM running. I keep getting a check sum error with the ova file. and VDI files aren’t compatible. I do not know what is so different this time around. :S
On one hand I’m happy to report this crash is not the fault of HA. On the other hand I’m deeply concerned about what actually caused it. My qnap nas has been corrupting files. which explained the check sum errors. I finally figured it out when I couldn’t unzip files that I had freshly downloaded from the internet when I saved them to the file server but if I saved them to my PC they were fine.
I did save a copy of the VM that had my old install of HA. But Im willing to bet the database is badly corrupted.
So I was able to get the old VM booting again. However the database tables are corrupt. Is there anyway to repair this? I’ve tried repacking, and i’ve tried using the cli to optimize mariadb. repacking didn’t do anything and optimizing threw an error.
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1964, in _exec_single_context
self.dialect.do_execute(
File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/default.py", line 748, in do_execute
cursor.execute(statement, parameters)
File "/usr/local/lib/python3.10/site-packages/MySQLdb/cursors.py", line 206, in execute
res = self._query(query)
File "/usr/local/lib/python3.10/site-packages/MySQLdb/cursors.py", line 319, in _query
db.query(q)
File "/usr/local/lib/python3.10/site-packages/MySQLdb/connections.py", line 254, in query
_mysql.connection.query(self, query)
MySQLdb.OperationalError: (1034, "Index for table 'statistics_short_term' is corrupt; try to repair it")