update backup cron bug
This commit is contained in:
+13
-5
@@ -1,9 +1,16 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
. /etc/profile
|
|
||||||
echo "Cron job triggered at $(date)" >> /var/log/cron/cron.log
|
|
||||||
echo 'started the backup'
|
|
||||||
export PGPASSWORD=$PG_PASSWORD
|
|
||||||
|
|
||||||
|
# Load environment variables
|
||||||
|
. /etc/profile
|
||||||
|
|
||||||
|
# Debugging output
|
||||||
|
echo "Cron environment:" >> /var/log/cron/cron.log
|
||||||
|
env >> /var/log/cron/cron.log
|
||||||
|
|
||||||
|
|
||||||
|
echo "Starting backup at $(date)" >> /var/log/cron/cron.log
|
||||||
|
|
||||||
|
export PGPASSWORD=$PG_PASSWORD
|
||||||
|
|
||||||
TELEGRAM_API="https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendDocument"
|
TELEGRAM_API="https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendDocument"
|
||||||
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
|
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
|
||||||
@@ -14,7 +21,7 @@ ZIP_FILE="backup_${TIMESTAMP}.zip"
|
|||||||
pg_dump -h $PG_HOST -p $PG_PORT -U $PG_USER -d $PG_DATABASE -w > /backups/$BACKUP_FILE
|
pg_dump -h $PG_HOST -p $PG_PORT -U $PG_USER -d $PG_DATABASE -w > /backups/$BACKUP_FILE
|
||||||
|
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "Backup failed!"
|
echo "Backup failed!" >> /var/log/cron/cron.log
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -25,3 +32,4 @@ curl -F chat_id=$TELEGRAM_CHAT_ID \
|
|||||||
|
|
||||||
ls -t /backups/*.zip | tail -n +4 | xargs rm -f
|
ls -t /backups/*.zip | tail -n +4 | xargs rm -f
|
||||||
ls -t /backups/*.sql | tail -n +4 | xargs rm -f
|
ls -t /backups/*.sql | tail -n +4 | xargs rm -f
|
||||||
|
echo "Backup completed at $(date)" >> /var/log/cron/cron.log
|
||||||
@@ -1,6 +1 @@
|
|||||||
# 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
|
* * * * * /app/backup.sh >> /var/log/cron/cron.log 2>&1
|
||||||
+8
-4
@@ -1,16 +1,20 @@
|
|||||||
FROM alpine:3.19
|
FROM alpine:3.19
|
||||||
|
|
||||||
RUN apk add --no-cache postgresql-client curl zip tzdata cron
|
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
|
|
||||||
|
|
||||||
|
|
||||||
|
RUN mkdir -p /app /var/log/cron
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY backup.sh .
|
COPY backup.sh .
|
||||||
COPY crontab /etc/crontabs/root
|
COPY crontab /etc/crontabs/root
|
||||||
|
|
||||||
RUN chmod +x backup.sh && \
|
RUN chmod +x backup.sh && \
|
||||||
chmod 0644 /etc/crontabs/root && \
|
chmod 0644 /etc/crontabs/root && \
|
||||||
touch /var/log/cron/cron.log
|
touch /var/log/cron/cron.log && \
|
||||||
|
chmod 666 /var/log/cron/cron.log
|
||||||
|
|
||||||
CMD ["sh", "-c", "crond -l 8 -L /var/log/cron/cron.log -f"]
|
|
||||||
|
RUN printenv | grep -E 'PG_|TELEGRAM_' >> /etc/environment
|
||||||
|
|
||||||
|
|
||||||
|
CMD ["sh", "-c", "crond -f -l 0 -L /var/log/cron/cron.log"]
|
||||||
Reference in New Issue
Block a user