Skip to content

Add backup and restore of sensors, history and settings - #95

Open
elvenpath wants to merge 9 commits into
emericg:masterfrom
elvenpath:feature/database-backup
Open

elvenpath wants to merge 9 commits into
emericg:masterfrom
elvenpath:feature/database-backup

Conversation

@elvenpath

Copy link
Copy Markdown

This adds backup and restore, so you can move everything (sensors, plants, history and settings) to another phone or computer.

  • Settings has a new "Backup" section with "Back up" and "Restore" buttons. On desktop, Back up opens a Save dialog. On Android/iOS it opens the share sheet, like the CSV export does.
  • The three empty device-list screens also get a "Restore a backup" button, so a fresh install can restore right away.
  • The backup is a single SQLite file: a VACUUM INTO copy of data.db, plus two small tables for the settings and the backup date/app version.
  • When restoring, a popup shows what's in the file (date, number of sensors, history range) and lets you restore the data, the settings, or both. It replaces the current data, there's no merging. Only backups with the current schema (v3) are accepted.

The restore runs in one transaction on the open database instead of swapping the file, because the Android service keeps its own connection open. If anything fails it rolls back and nothing changes. Devices are unloaded and reloaded around it, so no restart is needed. Machine-specific settings (window size, notification/systray/Bluetooth toggles, MySQL/MQTT credentials) are not included. Everything is hidden in MySQL mode.

Some notes:

  • saveDatabase() without argument (the disabled button in Advanced settings) now writes to the app cache instead of ~/WatchFlower.
  • On iOS/macOS the device address is a per-host UUID, so after moving a backup between Apple devices (or Apple and non-Apple) the sensors won't reconnect and need a new scan. Names and history are kept.
  • On Android, sendFile copies the file using baseName(), so the shared file loses its .db extension. The CSV export has the same issue, I didn't touch MobileSharing.
  • Restoring over existing sensors prints a bunch of "Cannot read property ... of null" errors from DeviceWidget.qml. It's the same thing "Remove sensor" does today.
  • This is the first use of QtQuick.Dialogs and QtCore in the QML, in case the deploy scripts need something.

Tested on Linux with Qt 6.10.3, desktop and mobile layouts, plus a small local test program for the database side (rollback, locked database, wrong files). I haven't tried it on Android, iOS, Windows, macOS or the Flatpak.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant