mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-11-03 03:35:04 +03:00
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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user