From 6c68d3f4b8206a811bc67970c8ecf537e83c45b7 Mon Sep 17 00:00:00 2001 From: Parsa Nazer Date: Mon, 24 Feb 2025 23:35:42 +0330 Subject: [PATCH] docker sculated time --- backup/backup.sh | 2 ++ backup/crontab | 7 ++++++- backup/dockerfile | 16 +++++++++++++--- docker-compose.yml | 2 +- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/backup/backup.sh b/backup/backup.sh index 99b6963..8ad0be7 100644 --- a/backup/backup.sh +++ b/backup/backup.sh @@ -1,4 +1,6 @@ #!/bin/sh +. /etc/profile +echo "Cron job triggered at $(date)" >> /var/log/cron/cron.log echo 'started the backup' export PGPASSWORD=$PG_PASSWORD diff --git a/backup/crontab b/backup/crontab index 5c39650..11df74a 100644 --- a/backup/crontab +++ b/backup/crontab @@ -1 +1,6 @@ -* * * * * /app/backup.sh \ No newline at end of file +# Add this line for environment variables +SHELL=/bin/sh +PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin + +# Schedule (runs every minute for testing) +* * * * * /app/backup.sh >> /var/log/cron/cron.log 2>&1 \ No newline at end of file diff --git a/backup/dockerfile b/backup/dockerfile index 701f401..391b3d5 100644 --- a/backup/dockerfile +++ b/backup/dockerfile @@ -1,6 +1,16 @@ FROM alpine:3.19 -RUN apk add --no-cache postgresql-client curl zip tzdata + +RUN apk add --no-cache postgresql-client curl zip tzdata cron +RUN ln -sf /usr/share/zoneinfo/UTC /etc/localtime +RUN mkdir -p /var/log/cron + + WORKDIR /app COPY backup.sh . -RUN chmod +x backup.sh -CMD ["/app/backup.sh"] \ No newline at end of file +COPY crontab /etc/crontabs/root + +RUN chmod +x backup.sh && \ + chmod 0644 /etc/crontabs/root && \ + touch /var/log/cron/cron.log + +CMD ["sh", "-c", "crond -l 8 -L /var/log/cron/cron.log -f"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index edfab7e..ff1d39c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -52,7 +52,7 @@ services: - PG_PORT=5432 - PG_DATABASE=hshop - PG_USER=byeto - - PG_PASSWORD=vuhbyq-cypMu0-sirbon # Remove single quotes here + - PG_PASSWORD=vuhbyq-cypMu0-sirbon - TELEGRAM_BOT_TOKEN=7068288679:AAGecMnyt9A6R78OQu8nQeISMK1LepX718g - TELEGRAM_CHAT_ID=1198382521 volumes: