mirror of
https://github.com/Dispatcharr/Dispatcharr.git
synced 2026-01-23 02:35:14 +00:00
Use system timezone for backup filenames
Updated create_backup to use the system's configured timezone for backup filenames instead of always using UTC. This makes filenames more intuitive and matches users' local time expectations. Changes: - Import pytz and CoreSettings - Get system timezone from CoreSettings.get_system_time_zone() - Convert current UTC time to system timezone for filename timestamp - Fallback to UTC if timezone conversion fails - Internal metadata timestamps remain UTC for consistency Example: - System timezone: America/New_York (EST) - Created at 3:00 PM EST - Old filename: dispatcharr-backup-2025.12.09.20.00.00.zip (UTC time) - New filename: dispatcharr-backup-2025.12.09.15.00.00.zip (local time) This aligns with the timezone-aware scheduling already implemented.
This commit is contained in:
parent
795934dafe
commit
8388152d79
1 changed files with 13 additions and 1 deletions
|
|
@ -7,8 +7,10 @@ import tempfile
|
|||
from pathlib import Path
|
||||
from zipfile import ZipFile, ZIP_DEFLATED
|
||||
import logging
|
||||
import pytz
|
||||
|
||||
from django.conf import settings
|
||||
from core.models import CoreSettings
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
|
@ -183,7 +185,17 @@ def create_backup() -> Path:
|
|||
Returns the path to the created backup file.
|
||||
"""
|
||||
backup_dir = get_backup_dir()
|
||||
timestamp = datetime.datetime.now(datetime.UTC).strftime("%Y.%m.%d.%H.%M.%S")
|
||||
|
||||
# Use system timezone for filename (user-friendly), but keep internal timestamps as UTC
|
||||
system_tz_name = CoreSettings.get_system_time_zone()
|
||||
try:
|
||||
system_tz = pytz.timezone(system_tz_name)
|
||||
now_local = datetime.datetime.now(datetime.UTC).astimezone(system_tz)
|
||||
timestamp = now_local.strftime("%Y.%m.%d.%H.%M.%S")
|
||||
except Exception as e:
|
||||
logger.warning(f"Failed to use system timezone {system_tz_name}: {e}, falling back to UTC")
|
||||
timestamp = datetime.datetime.now(datetime.UTC).strftime("%Y.%m.%d.%H.%M.%S")
|
||||
|
||||
backup_name = f"dispatcharr-backup-{timestamp}.zip"
|
||||
backup_file = backup_dir / backup_name
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue