[PR #6137] [MERGED] fix(database): create SQLite backup snapshots online #6100

Closed
opened 2026-11-02 04:06:21 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/6137
Author: @PathGao
Created: 7/29/2026
Status: ✅ Merged
Merged: 7/29/2026
Merged by: @MHSanaei

Base: main ← Head: fix-sqlite-backup-snapshot-v2


📝 Commits (5)

  • ee316a2 fix(database): snapshot SQLite backups online
  • a771784 style(database): group SQLite driver imports
  • 3e8abe7 fix(database): bound online backup retries
  • e2b1c74 test(database): cover existing backup destinations
  • a348c9d fix(database): harden SQLite snapshot lifecycle

📊 Changes

6 files changed (+334 additions, -70 deletions)

View changed files

📝 go.mod (+1 -1)
➕ internal/database/backup_test.go (+186 -0)
📝 internal/database/db.go (+113 -5)
📝 internal/database/journal_mode_test.go (+0 -41)
📝 internal/web/service/server.go (+18 -16)
📝 internal/web/service/tgbot/tgbot_report.go (+16 -7)

📄 Description

Problem

SQLite downloads and SQLite migration exports previously ran a WAL checkpoint and then read the live database file. A commit between those operations could produce a copy that does not represent a single SQLite state.

Change

  • Create the copy with SQLite's online backup API before reading or dumping it.
  • Use a private temporary directory beside the database and remove it through an explicit cleanup function.
  • Sweep interrupted snapshot directories when SQLite starts.
  • Use a single backup step in WAL mode; use bounded incremental steps for the supported DELETE journal mode.
  • Bound connection acquisition and retry handling.
  • Reuse one scheduled Telegram snapshot across all administrators.
  • Remove the checkpoint helper, whose only production callers were these two paths.

Regression coverage

  • Snapshot integrity and exact committed rows while another goroutine writes.
  • Timeout while the source pool has no available connection.
  • Existing destinations are rejected without overwriting them.
  • Journal-mode step selection and startup cleanup of interrupted snapshot directories.

Validated locally with go test -race -shuffle=on -count=1 ./internal/database ./internal/web/service/tgbot, go vet for those packages, and golangci-lint run.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/6137 **Author:** [@PathGao](https://github.com/PathGao) **Created:** 7/29/2026 **Status:** ✅ Merged **Merged:** 7/29/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `fix-sqlite-backup-snapshot-v2` --- ### 📝 Commits (5) - [`ee316a2`](https://github.com/MHSanaei/3x-ui/commit/ee316a21bc1fd44752b7b9a446868f4fd0b12dfd) fix(database): snapshot SQLite backups online - [`a771784`](https://github.com/MHSanaei/3x-ui/commit/a771784f4e5fe26baf33c6c315cdf79b631da5c5) style(database): group SQLite driver imports - [`3e8abe7`](https://github.com/MHSanaei/3x-ui/commit/3e8abe7664771dcfab144700d83fe551d8b41e43) fix(database): bound online backup retries - [`e2b1c74`](https://github.com/MHSanaei/3x-ui/commit/e2b1c743b76db8ad79e1e01f1c880a6a19ab5928) test(database): cover existing backup destinations - [`a348c9d`](https://github.com/MHSanaei/3x-ui/commit/a348c9dd4a3d5d848ca8e4a8997f822315c52a19) fix(database): harden SQLite snapshot lifecycle ### 📊 Changes **6 files changed** (+334 additions, -70 deletions) <details> <summary>View changed files</summary> 📝 `go.mod` (+1 -1) ➕ `internal/database/backup_test.go` (+186 -0) 📝 `internal/database/db.go` (+113 -5) 📝 `internal/database/journal_mode_test.go` (+0 -41) 📝 `internal/web/service/server.go` (+18 -16) 📝 `internal/web/service/tgbot/tgbot_report.go` (+16 -7) </details> ### 📄 Description ## Problem SQLite downloads and SQLite migration exports previously ran a WAL checkpoint and then read the live database file. A commit between those operations could produce a copy that does not represent a single SQLite state. ## Change - Create the copy with SQLite's online backup API before reading or dumping it. - Use a private temporary directory beside the database and remove it through an explicit cleanup function. - Sweep interrupted snapshot directories when SQLite starts. - Use a single backup step in WAL mode; use bounded incremental steps for the supported DELETE journal mode. - Bound connection acquisition and retry handling. - Reuse one scheduled Telegram snapshot across all administrators. - Remove the checkpoint helper, whose only production callers were these two paths. ## Regression coverage - Snapshot integrity and exact committed rows while another goroutine writes. - Timeout while the source pool has no available connection. - Existing destinations are rejected without overwriting them. - Journal-mode step selection and startup cleanup of interrupted snapshot directories. Validated locally with `go test -race -shuffle=on -count=1 ./internal/database ./internal/web/service/tgbot`, `go vet` for those packages, and `golangci-lint run`. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:06:21 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#6100
No description provided.