fix(server): honor keepHostSettings for SQLite imports into PostgreSQL (#6995)

importPostgresDB forwarded keepHostSettings only for native PostgreSQL dumps; both SQLite branches dropped it, so importing a .db or SQL dump copied the source's ports, paths, certificates and node identity over the destination's. Both formats now capture the host-bound settings first and restore them after a successful migration. CI runs the new integration test against PostgreSQL. Fixes #6993.
This commit is contained in:
Hamed
2026-11-02 17:43:58 +03:30
committed by GitHub
parent 4180899f15
commit d2450e103c
3 changed files with 296 additions and 3 deletions
+11 -3
View File
@@ -2147,9 +2147,9 @@ func (s *ServerService) importPostgresDB(file multipart.File, keepHostSettings b
case importKindPgDump:
return s.restorePostgresDump(file, keepHostSettings)
case importKindSQLiteDB:
return s.migrateSQLiteIntoPostgres(file, false)
return s.migrateSQLiteIntoPostgres(file, false, keepHostSettings)
case importKindSQLiteDump:
return s.migrateSQLiteIntoPostgres(file, true)
return s.migrateSQLiteIntoPostgres(file, true, keepHostSettings)
default:
return common.NewError("Invalid file: expected a PostgreSQL custom-format dump (.dump) from this panel's Back Up, a SQLite database (.db), or a SQLite migration dump")
}
@@ -2231,7 +2231,7 @@ func (s *ServerService) restorePostgresDump(file multipart.File, keepHostSetting
return nil
}
func (s *ServerService) migrateSQLiteIntoPostgres(file multipart.File, isSQLDump bool) error {
func (s *ServerService) migrateSQLiteIntoPostgres(file multipart.File, isSQLDump, keepHostSettings bool) error {
tempDir, err := os.MkdirTemp("", "x-ui-pg-migrate-*")
if err != nil {
return common.NewErrorf("Error creating temporary folder: %v", err)
@@ -2272,6 +2272,11 @@ func (s *ServerService) migrateSQLiteIntoPostgres(file multipart.File, isSQLDump
logger.Warningf("Failed to stop Xray before DB restore: %v", errStop)
}
var keptSettings hostBoundSnapshot
if keepHostSettings {
keptSettings = captureHostBoundSettings()
}
if errClose := database.CloseDB(); errClose != nil {
logger.Warningf("Failed to close existing DB before restore: %v", errClose)
}
@@ -2281,6 +2286,9 @@ func (s *ServerService) migrateSQLiteIntoPostgres(file multipart.File, isSQLDump
if errInit := database.InitDB(config.GetDBPath()); errInit != nil {
return common.NewErrorf("Restore finished but reopening the database failed: %v", errInit)
}
if migrateErr == nil {
restoreHostBoundSettings(keptSettings)
}
s.inboundService.MigrateDB()
if migrateErr != nil {