Skip to content

DB_DUMP_BEGIN should respect container timezone (TZ environment variable) #509

@padixa

Description

@padixa

Current Behavior

When setting a timezone in the container (via TZ environment variable or /etc/localtime volume mount), the DB_DUMP_BEGIN time is still interpreted as UTC time, not local time.

Example configuration:

environment:
  TZ: Asia/Shanghai
  DB_DUMP_BEGIN: "0400"  # Expected: 04:00 Shanghai time

Actual result:

Backup runs at UTC 04:00 = Shanghai 12:00 (8 hours later than expected)
Filename includes timezone offset: db_backup_2026-03-12T12:00:38+08:00.tgz

Expected Behavior

When TZ is set, DB_DUMP_BEGIN should be interpreted in the container's local timezone, not UTC.

Expected result:

  • Backup runs at Shanghai 04:00 (as configured)
  • Filename reflects local time: db_backup_2026-03-12T04:00:38+08:00.tgz

Workaround

Currently, users must manually calculate UTC offset:

environment:
  TZ: Asia/Shanghai
  DB_DUMP_BEGIN: "2000"  # UTC 20:00 = Shanghai 04:00 (next day)

This is confusing and error-prone, especially during daylight saving time changes.

Proposed Solution

Parse DB_DUMP_BEGIN using the container's local timezone when TZ is set:

// In pkg/core/dump.go or scheduler
var loc *time.Location
if tz := os.Getenv("TZ"); tz != "" {
    loc, _ = time.LoadLocation(tz)
} else {
    loc = time.UTC
}
// Parse DB_DUMP_BEGIN in the local timezone

Environment

Image: databack/mysql-backup:latest
Docker Compose configuration with TZ=Asia/Shanghai
Observed in production environment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions