[GH-ISSUE #5584] Telegram backup: add date prefix to backup filename #3902

Closed
opened 2026-10-31 20:35:46 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @acidmsg on GitHub (Jun 26, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5584

Originally assigned to: @NikanZeyaei on GitHub.

Problem:
The bot sends database backups via DM. Over time, backup files accumulate with identical filenames (<domain>.db or x-ui.db). It is impossible to distinguish a fresh backup from an old one without downloading — filenames contain no date.

Proposed solution:
Add a YYYY-MM-DD_ prefix to the filename. Example: 2026-06-25_<domain>.db.

Where to change:
internal/web/service/server.go — BackupFilename().

Possible implementation (verified against current v3.4.0 code):

func (s *ServerService) BackupFilename(requestHost string) string {
    ext := ".db"
    if database.IsPostgres() {
        ext = ".dump"
    }
    prefix := time.Now().Format("2006-01-02") + "_"
    return prefix + s.backupHost(requestHost) + ext
}

time is already imported in the package. The function signature and all call sites remain compatible.

Alternatively, this could be made configurable via panel settings (tgBotBackupPrefix: "datetime" | "none") for backward compatibility.

Originally created by @acidmsg on GitHub (Jun 26, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5584 Originally assigned to: @NikanZeyaei on GitHub. **Problem:** The bot sends database backups via DM. Over time, backup files accumulate with identical filenames (`<domain>.db` or `x-ui.db`). It is impossible to distinguish a fresh backup from an old one without downloading — filenames contain no date. **Proposed solution:** Add a `YYYY-MM-DD_` prefix to the filename. Example: `2026-06-25_<domain>.db`. **Where to change:** `internal/web/service/server.go` — `BackupFilename()`. **Possible implementation (verified against current v3.4.0 code):** ```go func (s *ServerService) BackupFilename(requestHost string) string { ext := ".db" if database.IsPostgres() { ext = ".dump" } prefix := time.Now().Format("2006-01-02") + "_" return prefix + s.backupHost(requestHost) + ext } ``` `time` is already imported in the package. The function signature and all call sites remain compatible. Alternatively, this could be made configurable via panel settings (`tgBotBackupPrefix: "datetime" | "none"`) for backward compatibility.
bsakaguchi 2026-10-31 20:35:46 +07:00
Author
Owner

@github-actions[bot] commented on GitHub (Jun 26, 2026):

The technical analysis in this report is accurate. Here is what the source confirms:

Current behavior (verified in source)

internal/web/service/server.go:1307-1313 — BackupFilename currently returns <host>.db (SQLite) or <host>.dump (PostgreSQL) with no temporal component. The host portion is derived from the request host, configured listen domain, or resolved public IP via backupHost().

Proposed change is viable as written

  • time is already imported at line 27 of internal/web/service/server.go.
  • The date string produced by time.Now().Format("2006-01-02") contains only digits and hyphens; combined with the _ separator, the resulting prefix 2026-06-26_ matches the filename safety regex ^[a-zA-Z0-9_\-.]+$ enforced at internal/web/controller/server.go:22. No validation change is needed.
  • Both call sites — the HTTP download handler (internal/web/controller/server.go:326) and the Telegram bot (internal/web/service/tgbot/tgbot_report.go:405) — pass through BackupFilename unchanged; function signature is unmodified.

One point to consider before submitting a PR

The Telegram bot (tgbot_report.go:405) passes "" as requestHost, so the backup message already includes the timestamp in its text body (tgbot.messages.backupTime, line 399). Adding the date to the filename is still useful for distinguishing files in the chat history, but it is worth noting in the PR description so maintainers can weigh the duplication.

The configurable prefix alternative mentioned in the report ("datetime" | "none") would add a settings schema entry, migration, and UI work. A simpler unconditional prefix is a reasonable starting point and easier to review; the configurable variant could follow as a separate request if demand exists.

A PR implementing the single-line change to BackupFilename can be submitted against main.

This reply was generated automatically; a maintainer may follow up.

<!-- gh-comment-id:4807426770 --> @github-actions[bot] commented on GitHub (Jun 26, 2026): The technical analysis in this report is accurate. Here is what the source confirms: **Current behavior (verified in source)** `internal/web/service/server.go:1307-1313` — `BackupFilename` currently returns `<host>.db` (SQLite) or `<host>.dump` (PostgreSQL) with no temporal component. The host portion is derived from the request host, configured listen domain, or resolved public IP via `backupHost()`. **Proposed change is viable as written** - `time` is already imported at line 27 of `internal/web/service/server.go`. - The date string produced by `time.Now().Format("2006-01-02")` contains only digits and hyphens; combined with the `_` separator, the resulting prefix `2026-06-26_` matches the filename safety regex `^[a-zA-Z0-9_\-.]+$` enforced at `internal/web/controller/server.go:22`. No validation change is needed. - Both call sites — the HTTP download handler (`internal/web/controller/server.go:326`) and the Telegram bot (`internal/web/service/tgbot/tgbot_report.go:405`) — pass through `BackupFilename` unchanged; function signature is unmodified. **One point to consider before submitting a PR** The Telegram bot (tgbot_report.go:405) passes `""` as `requestHost`, so the backup message already includes the timestamp in its text body (`tgbot.messages.backupTime`, line 399). Adding the date to the filename is still useful for distinguishing files in the chat history, but it is worth noting in the PR description so maintainers can weigh the duplication. The configurable prefix alternative mentioned in the report (`"datetime" | "none"`) would add a settings schema entry, migration, and UI work. A simpler unconditional prefix is a reasonable starting point and easier to review; the configurable variant could follow as a separate request if demand exists. A PR implementing the single-line change to `BackupFilename` can be submitted against `main`. *This reply was generated automatically; a maintainer may follow up.*
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#3902
No description provided.