Source: Dev.to | Jan 09, 2026 (UTC)
Imagine the following scenario: you created a script in bash to create a backup of a production database, say, an online store. After creating the script and adding it to crontab, everything worked flawlessly. After some time, say a month, the database became corrupted, for example, due to the installation of a faulty plugin. At that moment, you want to retrieve an updated database backup from last night and discover that the last database backup is from two weeks ago. What happened? Everything was working fine.
This nightmare scenario is more common than you might think, and perhaps it has even affected you personally. Scripts added to crontab fail without warning, causing so-called “silent errors.” They can be caused by a variety of reasons, such as a full disk, permission changes, network timeouts, expired credentials, or simply a typo after a “quick fix.”
The Problem with Unmonitored Backups
Traditional cron jobs have a fundamental flaw: they only report an error when they fail to run. For example, your backup script might fail:
- Run successfully but exit with errors
- Exit but generate empty or corrupted files
- Run but take 10 times longer than expected (a sign of problems)
- Skip tables due to permission issues
Before you know it, your backup retention period might expire—leaving you without any valid backups.
The solution is simple: your backup script should actively report its status to an external monitor. Here’s how to integrate database backups with CronMonitor.
#!/bin/bash MONITOR_URL="https://cronmonitor.app/api/ping/your-unique-id" BACKUP_DIR="/backups/mysql" DATE=$(date +%Y%m%d_%H%M%S) DB_NAME="production" # Signal start curl -s "${MONITOR_URL}/start" # Perform backup mysqldump --single-transaction \ --routines \ --triggers \ "$DB_NAME" | gzip > "${BACKUP_DIR}/${DB_NAME}_${DATE}.sql.gz" # Check if backup was successful and file is not empty if [ $? -eq 0 ] && [ -s "${BACKUP_DIR}/${DB_NAME}_${DATE}.sql.gz" ]; then # Clean old backups (keep last 7 days) find "$BACKUP_DIR" -name "*.sql.gz" -mtime +7 -delete # Signal success curl -s "${MONITOR_URL}/complete" else # Signal failure curl -s "${MONITOR_URL}/fail" exit 1 fi
Enter fullscreen mode
Exit fullscreen mode


Залишити відповідь