update backup cron bug
This commit is contained in:
+14
-6
@@ -1,9 +1,16 @@
|
||||
#!/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"
|
||||
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
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Backup failed!"
|
||||
echo "Backup failed!" >> /var/log/cron/cron.log
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -24,4 +31,5 @@ curl -F chat_id=$TELEGRAM_CHAT_ID \
|
||||
$TELEGRAM_API
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user