mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[GH-ISSUE #6993] [Bug]: SQLite-to-PostgreSQL import ignores Keep this machine's settings #4610
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#4610
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @HamedSanaei on GitHub (Oct 28, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6993
Describe the bug
On a PostgreSQL-backed 3x-ui panel, importing a SQLite
.dbbackup or SQLite SQL migration.dumpignores the "Keep this machine's settings" checkbox (checked by default). Unlike the native PostgreSQLpg_dumprestore path, it silently replaces the destination panel's host-specific settings with values from the source machine.This may overwrite the destination's panel port, web base path, bind addresses, certificate paths and node identity, making the panel unreachable after migration.
Steps to reproduce
webPort=2053,webBasePath=/destination/..dbbackup from source A withwebPort=2087,webBasePath=/source/..dump.Expected behavior
With Keep this machine's settings enabled, destination B retains its own host-bound settings. Inbounds, clients, users and ordinary settings are imported from A. When the checkbox is disabled, importing A's host-bound settings is intentional.
Actual behavior (verified by code inspection)
Both SQLite input types bypass the flag and replace the destination
settingstable. The host settings are not captured/restored. A dedicated end-to-end reproduction is still needed.Root cause
internal/web/service/server.go:migrateSQLiteIntoPostgres(file, isSQLDump)does not acceptkeepHostSettings, does not callcaptureHostBoundSettings(), and does not callrestoreHostBoundSettings(). Instead it callsdatabase.MigrateData, which truncates and repopulates destination tables, includingsettings. In contrast, the native PostgreSQL dump restore path and the SQLite-backed import path honor the flag.The frontend already sends the checkbox value; the controller defaults it to true.
Suggested fix
keepHostSettingstomigrateSQLiteIntoPostgresfor both SQLite formats.keepHostSettings=falseas the intentional full-clone mode.Regression tests
Cover both
.dband SQLite SQL.dump→ PostgreSQL, each with keep=true/false. Assert that port, web base path, bind/certificate settings and node identity stay local when keep=true while normal data is imported. Include absent/empty setting keys and failed migrations.Related
Scope: SQLite → PostgreSQL migration only, not native PostgreSQL
pg_dumprestore.@github-actions[bot] commented on GitHub (Oct 28, 2026):
Confirmed: on a PostgreSQL-backed panel, importing a SQLite
.dbor a SQLite migration.dumpignores Keep this machine's settings. It replaces the destination's wholesettingstable with the source's, includingwebPort,webBasePath,secret,panelGuidand the node mTLS material.The checkbox value does reach the service.
BackupModal.tsx:49sendsformData.append('keepHostSettings', String(keepHostSettings)), and the controller reads it atinternal/web/controller/server.go:391withkeepHostSettings := c.Request.FormValue("keepHostSettings") != "false".importPostgresDBthen forwards the flag only to thepg_dumpbranch and drops it for both SQLite branches:The
false/truepassed there isisSQLDump, not the keep flag.migrateSQLiteIntoPostgres(server.go:2186) has nokeepHostSettingsparameter. It goes straight fromdatabase.CloseDB()todatabase.MigrateData(dbPath, config.GetDBDSN())(server.go:2231) and thendatabase.InitDB(server.go:2233), without callingcaptureHostBoundSettings()orrestoreHostBoundSettings().MigrateDatalists&model.Setting{}inmigrationModels()(internal/database/migrate_data.go:41). It runstruncatePostgresTables(tx, migrationModels())and thencopyTablefor each model (migrate_data.go:128-137), so the destination's settings rows are deleted and replaced with the source's.The other two import paths both do it correctly. The SQLite-panel import captures at
server.go:1878-1879and restores atserver.go:1937. Thepg_dumprestore captures atserver.go:2151-2152and restores atserver.go:2171.Workaround until this is fixed: after a SQLite → PostgreSQL import, the panel will listen on the source machine's port and base path. Reach it there, or reset them from the shell with
x-ui setting(e.g.x-ui setting -port 2053 -webBasePath /destination/). Then check the certificate paths and the sub-server settings.Verdict: Confirmed bug
Severity: High
Confidence: High
Root cause:
internal/web/service/server.go:2101-2104,importPostgresDB, dropskeepHostSettingsforimportKindSQLiteDB/importKindSQLiteDump.migrateSQLiteIntoPostgres(server.go:2186-2247) never snapshots or restores host-bound settings arounddatabase.MigrateData, which truncates and recopiessettings. This happens whenever the panel runs on PostgreSQL and the upload is a SQLite file, whatever the checkbox says. The SQLite → PostgreSQL branch came in with30b61161"feat: import SQLite migration dumps through the PostgreSQL panel restore", and the flag came in with6e80a468"feat(server): keep this machine's own settings when importing a database (#6227)". Both are first in v3.10.0, and the flag was never wired into this branch.Same class: None found.
ImportDB(SQLite panel,server.go:1878/1937) andrestorePostgresDump(server.go:2151/2171) both honour the flag. The only otherMigrateDatacaller,x-ui migrate-db --dsn(main.go:703), is a deliberate CLI full clone with no keep option.Already fixed: still present on the default branch (v3.11.0 tip)
Duplicate of: None (Related: #6227 introduced the option; #5004 the original request)
Evidence:
server.go:2102return s.migrateSQLiteIntoPostgres(file, false);server.go:2231migrateErr := database.MigrateData(dbPath, config.GetDBDSN());migrate_data.go:41&model.Setting{},;migrate_data.go:128truncatePostgresTables(tx, migrationModels()); contrastserver.go:2151-2152/2171inrestorePostgresDump.Not determined: I could not run this end to end. A Postgres-backed integration test importing a SQLite file with
webPortset differently on each side would confirm the overwrite at runtime.Suggested fix: Pass
keepHostSettingsfromimportPostgresDBintomigrateSQLiteIntoPostgres. When it is set, callcaptureHostBoundSettings()beforedatabase.CloseDB(), and callrestoreHostBoundSettings()afterdatabase.InitDBsucceeds, the same wayrestorePostgresDumpdoes. The existing helper already handles absent keys and the lazily minted mTLS keys (server.go:1794-1803), so no new logic is needed there.@MHSanaei
This reply was generated automatically by an issue analysis bot; a maintainer may follow up.