Skip to content

Fix handling of GSAK multi DB backups - #947

Merged
AgreeDK merged 4 commits into
OpenSAK-Org:betafrom
nagisml:improvement/gsak_import_of_backup
Oct 1, 2026
Merged

AgreeDK merged 4 commits into
OpenSAK-Org:betafrom
nagisml:improvement/gsak_import_of_backup

Conversation

@nagisml

@nagisml nagisml commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

see #946

GSAK import: support multi-database backups

A GSAK backup .zip holds one sqlite.db3 per database (plus gsak.db3 with the saved filters). Until now the import took only the first database and unpacked the whole backup to %TEMP% without removing it.

  • Lists every database in the backup (without unpacking it); the user picks which to import. Each target is named after its GSAK folder (editable) and is created if it doesn't exist.
  • Existing OpenSAK databases are only touched after confirmation: Overwrite / Merge / Skip.
  • Name clashes with stray files on disk are detected before the import starts (a free name like Default-2 is proposed instead).
  • Imports one database at a time: unpack → import → delete the temp copy. A failing database is logged and skipped rather than aborting the run.
  • If gsak.db3 is present, offers the existing GSAK filter import afterwards.
  • A single .db3 file or a zip with one database works as before (a one-row list).
  • Fix: load_gsak_filters() never closed gsak.db3, which kept the file locked on Windows.

Tested on a real 23-database / 9 GB backup; unit tests and mypy pass.

@AgreeDK

AgreeDK commented Oct 1, 2026

Copy link
Copy Markdown
Member

@nagisml
Thanks for this, it's a big improvement for everyone migrating from GSAK. This fixes #946.

I've tested it locally, both on its own and merged on top of beta: unit tests and mypy are green.

What I like:

  • Only one database is unpacked at a time, and the copy is removed afterwards. Before, extractall() copied the whole (possibly multi-GB) backup to the temp folder.
  • extract_gsak_member() always writes to dest_dir / basename, so a crafted member name can't escape the folder.
  • Skip is the default button when target databases already exist, not Overwrite.
  • clear_opensak_cache_data() covers all five tables with a foreign key to caches.
  • closing() around the sqlite connection fixes the Windows file lock.

A few things to consider (none of them blocking):

  1. Overwrite can't be undone. It's confirmed by a dialog, so it's acceptable for now. But it's a good example of why Backup is now PC - DT Filter is not displaying correctly #1 on the roadmap, and I'll keep it in mind when we design that.
  2. The worker switches the global database engine with init_db() in a background thread during the import. That pattern already existed on beta, so it's not new in this PR, but it now runs many times in a row for a multi-database import. The dialog is modal, so the risk is low. Just flagging it as a known weak spot.
  3. The distance fix in _switch_database recalculates synchronously on the GUI thread when distances aren't up to date. On a large database the UI may freeze briefly on the first switch after an import. Fine for now, but maybe a candidate for the background worker later.

Needed before merge: this PR conflicts with #948 in tests/e2e-tests/test_e2e_filter.py (all three of your PRs fix the same flaky test). I'll merge #948 first, since it reuses the existing wait_for_refresh() helper. Could you then rebase on beta and drop the change to that file?

I'll put fixes #946 in the merge commit message, so the issue closes when this reaches main.

@AgreeDK

AgreeDK commented Oct 1, 2026

Copy link
Copy Markdown
Member

@nagisml
Update: no need to rebase this one. I'll resolve the conflict in test_e2e_filter.py myself so we can get it merged. I'll keep the version from beta (from #948).

@AgreeDK
AgreeDK merged commit 61156c4 into OpenSAK-Org:beta Oct 1, 2026
7 checks passed
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.

2 participants