docker-db-auto-backup icon indicating copy to clipboard operation
docker-db-auto-backup copied to clipboard

Timezone for SCHEDULE

Open jkwek opened this issue 1 year ago • 2 comments

I've been playing with this excellent tool and it appears that the SCHEDULE environment variable always uses UTC time instead of my current timezone. I've tried various incarnations of setting the time through the volume /etc/localtime:/etc/localtime:ro and environment variable TZ=America/Los_Angeles (including both at the same time) but have not had success unless I set it to 8 hours ahead (since I'm in UTC -8). Am I missing something or does it only work in UTC time? Here is my docker compose (with both settings for time enabled):

services: backup: image: ghcr.io/realorangeone/db-auto-backup:latest restart: unless-stopped volumes: - /var/run/docker.sock:/var/run/docker.sock:ro - ./backups:/var/backups - /etc/localtime:/etc/localtime:ro environment: - SCHEDULE=48 14 * * * - TZ=America/Los_Angeles

jkwek avatar Feb 03 '25 23:02 jkwek

cron always uses UTC, so I think that's expected behaviour.

RealOrangeOne avatar Feb 04 '25 14:02 RealOrangeOne

I looked into this a bit more since my experience with cron is that it runs using the system time. I believe the python datetime is running as a "naive" object in this case since there is no timezone set (https://docs.python.org/3/library/datetime.html#aware-and-naive-objects). However the python-cron page does not state whether you can make this timezone-aware (https://pypi.org/project/python-cron/). If it is possible, this could be a potential future enhancement.

jkwek avatar Feb 05 '25 17:02 jkwek