Backup or externalize long term statistics

Hi all,

It happened to me more than once, between tests gone wrong and unreliable PCs, that I had to restore HomeAssistant from a backup… unfortunately, however, with each restore, I lost all the long term statistics.
Since some of them (car consumption, PV production, etc.) are quite interesting and I would hate to lose them, is there any way to externally save certain data (and restore them if needed) or otherwise have a backup that I can import after the backup?

Thanks

Assuming you have access to Samba, you can simply copy the 3 home-assistant_v2.db files to a safe location before the restore, apply the restore, shut down HA safely, then overwrite the db files which were restored with the ones you saved earlier.

Hello Christian

Maybe this?

Keeping lots of stuff is a likely cause of your crash and need to restore in the first place.

Here’s the spot where I usually jump in and explain how I save the data I want to keep long-term in a .csv file using the “File” integration.

Once the file is defined, I use action: notify.send_message in an automation to append a line to the file, formatted the way I want. That file can be backed up to a NAS or wherever you want to open it in any spreadsheet or data analysis software you’d like to use.

I have zero records in the LTS tables in my database. I never have to worry about losing them due to a restore or failure of HA. Hey, it works for me. YMMV.