feat(backup): name DB backup files after the server address

Panel downloads and Telegram backups were always named x-ui.db / x-ui.dump, so backups from different servers were indistinguishable. Name them after the panel address instead: the configured web domain, or the public IP (IPv4 before IPv6) when no domain is set, falling back to x-ui.

Centralized in ServerService.BackupFilename(); host is sanitized to the getDb filename charset (IPv6 colons become hyphens) and read from the mutex-guarded LastStatus to avoid racing the status goroutine.
This commit is contained in:
MHSanaei
2026-06-22 21:55:58 +02:00
parent 1b102ff9f7
commit a7e959ff49
4 changed files with 95 additions and 10 deletions
+1 -5
View File
@@ -8,7 +8,6 @@ import (
"strconv"
"time"
"github.com/mhsanaei/3x-ui/v3/internal/database"
"github.com/mhsanaei/3x-ui/v3/internal/database/model"
"github.com/mhsanaei/3x-ui/v3/internal/logger"
"github.com/mhsanaei/3x-ui/v3/internal/web/entity"
@@ -294,10 +293,7 @@ func (a *ServerController) getDb(c *gin.Context) {
return
}
filename := "x-ui.db"
if database.IsPostgres() {
filename = "x-ui.dump"
}
filename := a.serverService.BackupFilename()
if !filenameRegex.MatchString(filename) {
c.AbortWithError(http.StatusBadRequest, fmt.Errorf("invalid filename"))
return