evcc icon indicating copy to clipboard operation
evcc copied to clipboard

Automatic scheduled database backups (folder, SMB, WebDAV) – would a PR be welcome?

Open hermannthomas77 opened this issue 1 week ago β€’ 11 comments

Hi everyone,

I was inspired by the message on your site, and I quote:

We πŸ’š good UI We want to make smart energy management easy for everyone. Ideally, everything works without manual intervention or regular adjustments. But if you do want to see what the system is doing, we have a clean and responsive web interface ready to go.

I've built an automatic, scheduled database backups for evcc and would like to ask whether a PR would be welcome before opening one.

Branch: https://github.com/hermannthomas77/evcc/tree/feature/auto-backup (2 commits, rebased on current master)

Why in core?

I'm aware of #29221 and the feedback that backups can be pulled via the API, which is even easier now with API keys. That works well for people who already run a home server with cron jobs. Many evcc users don't: they run evcc on a Raspberry Pi or a small box, and the database holds their entire configuration and years of charging history. For them, a backup only happens if evcc does it itself, and today the missing backup is often noticed only after the SD card has failed. This kind of backup is the same way projects like Home Assistant do it too. Since the EVCC project wants to make things easy for everybody, this is a very important feature. I'm an IT guy myself, but I would like to be able to do this with a mouse click. Also, you already have the backup/restore feature, so why stop there? If you're being strict about it, you would have to remove that feature too, with the argument that users can back up and restore the config database manually. The end result would be the same.

The scope is deliberately limited: no cloud providers and no plug-in system for arbitrary targets. Three targets cover what most households have:

  • Folder: local directory, USB stick or a share mounted by the OS
  • SMB: NAS, FRITZ!Box
  • WebDAV: Synology, QNAP, Nextcloud

What it does

  • Daily or weekly at a set time, keeps the last N backups (default 7)
  • Consistent snapshot via VACUUM INTO, gzip compressed, optional password encryption (age/scrypt)
  • Catches up missed backups after a restart, retries failures after 15 min / 1 h / 4 h
  • New backupfailed notification event with a translated explanation of the error
  • Errors are classified and explained in the UI (DNS, connection refused, timeout, TLS, login, access denied, share not found, wrong password)
  • Card under Integrations showing target, last and next backup, stored backups and encryption state
  • Settings dialog with connection test and "Back up now"; SMB paths pasted from a file manager (smb://…, \\host\share) are split automatically
  • The existing restore dialog can restore directly from the backup target
  • Configurable via evcc.yaml or the UI; changes take effect after a restart like other settings

Dependencies

filippo.io/age, github.com/hirochachacha/go-smb2, github.com/studio-b12/gowebdav. All pure Go, no cgo.

Testing

  • Unit tests per target, for error classification, scheduling, retry and encryption
  • Round-trip tests (backup β†’ prune β†’ list β†’ download β†’ decrypt) for folder and an in-process WebDAV server; optionally against real servers via EVCC_TEST_FOLDER, EVCC_TEST_SMB and EVCC_TEST_WEBDAV
  • Manually tested against a Synology NAS (WebDAV), a FRITZ!Box (SMB) and a local folder, including restore
  • Playwright tests for configuration, failed and overdue states and restore from target; the full e2e suite passes on current master
  • golangci-lint clean; strings in en and de, other languages via Weblate

Size and options

45 files, about 5,400 lines, of which about 1,700 are tests and 400 generated (OpenAPI, go.sum). I'm happy to adapt it, for example:

  1. split into smaller PRs (core + folder target + API, then SMB/WebDAV, then UI), or
  2. drop SMB and WebDAV entirely and keep only the folder target, since network shares can also be mounted by the OS.

Screenshots

1-card 1-integrations 2-settings 3-restore

Would this be welcome in evcc? I'm open to any changes in scope or design.

I wrote the code together with Claude Code and have tested it on my own devices.

Best, Hermann

hermannthomas77 avatar Nov 22 '26 12:11 hermannthomas77

Thanks for the detailed proposal. This is a feature request and a scope decision for the maintainers, so there is nothing to analyze in the code yet.

Related: #29221 (closed PR for automated FTP/FTPS database backup), which you already reference. The earlier feedback there was that backups can be pulled via the API.

Points the maintainers will probably weigh: the size of the change (45 files, about 5,400 lines, three new dependencies) and whether SMB/WebDAV belong in core or whether a folder target only is enough. Your two options (split into smaller PRs, or folder target only) both address that.

πŸ€– Generated with Claude Code

github-actions[bot] avatar Nov 22 '26 12:11 github-actions[bot]

Discussed before. I don't see this as part of evcc.

andig avatar Nov 22 '26 16:11 andig

I have the feeling a lot of people like this for its simplicity. And simplicity is one of EVCC's goals, as far as I can tell. What are the reasons against this?

hermannthomas77 avatar Nov 22 '26 17:11 hermannthomas77

I don't want to nag, but I'm honestly trying to understand the difference between this and the other integrations. From both a technical and a usability point of view, they all seem pretty similar in how necessary they are to users.

Could you help me understand what makes this integration different?

hermannthomas77 avatar Nov 22 '26 18:11 hermannthomas77

Good idea - would suggest a new consideration - normal users tend to forget regular backups - and they have a big issue, when the SD Card crashes…

TeutoRockA avatar Nov 23 '26 07:11 TeutoRockA

I do believe a scheduled backup feature would make a lot of sense for evcc. Esp. since evcc started to collect metric, I expect this to increase wear on the SDCards (which a lot of installations on a Raspberry are likely running on). Even I keep forgetting to pull backups manually, I would welcome an option to have them generated automatically and stored on another system, perhaps even cloud services like OneDrive.

MartinRinas avatar Nov 23 '26 07:11 MartinRinas

@MartinRinas I did consider Google Drive and OneDrive. However, it is a harder process, both to develop and for the user. Once the first steps are done, I am happy to look into that further.

hermannthomas77 avatar Nov 23 '26 09:11 hermannthomas77

I've done something similar with backup to OneDrive earlier with openWB, there are libraries we could use. Happy to take a pass on that once there's agreement to do this.

MartinRinas avatar Nov 23 '26 09:11 MartinRinas

Adding a plethora of backup targets is certainly not what we'd want to implement. Backup doesn't belong into every implementation, it belongs into the OS.

andig avatar Nov 23 '26 10:11 andig

"Backup doesn't belong into every implementation, it belongs into the OS."

Home Assistant does it too.

I can also imagine EVCC becoming the default software that PV installers set up for their customers. In that case, the end customer won't be going to the OS level to configure backups.

hermannthomas77 avatar Nov 23 '26 10:11 hermannthomas77

HA is the OS/platform.

andig avatar Nov 23 '26 11:11 andig