From 8388152d79aef204f7015300c2da4cfbbceffeae Mon Sep 17 00:00:00 2001 From: Jim McBride Date: Tue, 9 Dec 2025 09:06:22 -0600 Subject: [PATCH] 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. --- apps/backups/services.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/apps/backups/services.py b/apps/backups/services.py index d3d1a767..b99fab6d 100644 --- a/apps/backups/services.py +++ b/apps/backups/services.py @@ -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