So, I did another backup last night from the Pi, and restored it onto the VM.
It showed the database in /config was not corrupt, and I had all my history visible properly. I went to sleep happy around at 1am as this meant both the backup and restores had succeeded.
Then, this morning, I logged in to HA and all the prior sensor history prior to 4am was gone. And the database had been moved to corrupt state at 4:12am. Seems like there is a bug in HA, and it looks like I have to go back to my Pi one more time.
edit: there is an automatic backup at 1:55am of about 900MB on the VM (made by the Samba backup add-on), which proves the DB had been initially restored properly.
edit: found this in the system log on the VM :
Logger: homeassistant.components.recorder.core
Source: components/recorder/purge.py:250
Integration: Recorder (documentation, issues)
First occurred: 04:12:27 (1 occurrences)
Last logged: 04:12:27
Unrecoverable sqlite3 database corruption detected: (sqlite3.DatabaseError) database disk image is malformed (Background on this error at: https://sqlalche.me/e/20/4xp6)
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/cursor.py", line 1140, in fetchall
rows = dbapi_cursor.fetchall()
sqlite3.DatabaseError: database disk image is malformed
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/recorder/core.py", line 895, in _process_one_task_or_recover
return task.run(self)
File "/usr/src/homeassistant/homeassistant/components/recorder/tasks.py", line 113, in run
if purge.purge_old_data(
File "/usr/src/homeassistant/homeassistant/components/recorder/util.py", line 608, in wrapper
return job(instance, *args, **kwargs)
File "/usr/src/homeassistant/homeassistant/components/recorder/purge.py", line 89, in purge_old_data
has_more_to_purge |= _purge_states_and_attributes_ids(
File "/usr/src/homeassistant/homeassistant/components/recorder/purge.py", line 193, in _purge_states_and_attributes_ids
state_ids, attributes_ids = _select_state_attributes_ids_to_purge(
File "/usr/src/homeassistant/homeassistant/components/recorder/purge.py", line 250, in _select_state_attributes_ids_to_purge
).all():
File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/result.py", line 1388, in all
return self._allrows()
File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/result.py", line 557, in _allrows
rows = self._fetchall_impl()
File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/result.py", line 2291, in _fetchall_impl
return list(self.iterator)
File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/loading.py", line 191, in chunks
fetch = cursor._raw_all_rows()
File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/result.py", line 548, in _raw_all_rows
rows = self._fetchall_impl()
File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/cursor.py", line 2108, in _fetchall_impl
return self.cursor_strategy.fetchall(self, self.cursor)
File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/cursor.py", line 1144, in fetchall
self.handle_exception(result, dbapi_cursor, e)
File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/cursor.py", line 1085, in handle_exception
result.connection._handle_dbapi_exception(
File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 2339, in _handle_dbapi_exception
raise sqlalchemy_exception.with_traceback(exc_info[2]) from e
File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/cursor.py", line 1140, in fetchall
rows = dbapi_cursor.fetchall()
sqlalchemy.exc.DatabaseError: (sqlite3.DatabaseError) database disk image is malformed
(Background on this error at: https://sqlalche.me/e/20/4xp6)
Logger: homeassistant.components.recorder.util
Source: components/recorder/purge.py:250
Integration: Recorder (documentation, issues)
First occurred: 04:12:27 (1 occurrences)
Last logged: 04:12:27
Error executing query: (sqlite3.DatabaseError) database disk image is malformed (Background on this error at: https://sqlalche.me/e/20/4xp6)
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/cursor.py", line 1140, in fetchall
rows = dbapi_cursor.fetchall()
sqlite3.DatabaseError: database disk image is malformed
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/recorder/util.py", line 130, in session_scope
yield session
File "/usr/src/homeassistant/homeassistant/components/recorder/purge.py", line 89, in purge_old_data
has_more_to_purge |= _purge_states_and_attributes_ids(
File "/usr/src/homeassistant/homeassistant/components/recorder/purge.py", line 193, in _purge_states_and_attributes_ids
state_ids, attributes_ids = _select_state_attributes_ids_to_purge(
File "/usr/src/homeassistant/homeassistant/components/recorder/purge.py", line 250, in _select_state_attributes_ids_to_purge
).all():
File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/result.py", line 1388, in all
return self._allrows()
File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/result.py", line 557, in _allrows
rows = self._fetchall_impl()
File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/result.py", line 2291, in _fetchall_impl
return list(self.iterator)
File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/loading.py", line 191, in chunks
fetch = cursor._raw_all_rows()
File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/result.py", line 548, in _raw_all_rows
rows = self._fetchall_impl()
File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/cursor.py", line 2108, in _fetchall_impl
return self.cursor_strategy.fetchall(self, self.cursor)
File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/cursor.py", line 1144, in fetchall
self.handle_exception(result, dbapi_cursor, e)
File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/cursor.py", line 1085, in handle_exception
result.connection._handle_dbapi_exception(
File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 2339, in _handle_dbapi_exception
raise sqlalchemy_exception.with_traceback(exc_info[2]) from e
File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/cursor.py", line 1140, in fetchall
rows = dbapi_cursor.fetchall()
sqlalchemy.exc.DatabaseError: (sqlite3.DatabaseError) database disk image is malformed
(Background on this error at: https://sqlalche.me/e/20/4xp6)