I'm using Percona's Xtrabackup tools to back up a database nightly. I wrote a wrapper script to keep the proper number of backups around, write the output to a log file, and email the log file if the backup dies. When I manually run the script as root, the log file is generated as expected. However, once I put it in cron, the log file is created, but no content is generated. Here's the relevant portion of the script (let me know if I should post the whole thing.
DATE=`date +%F-%H%M`
LOC=/var/mysqlbackups/dbBackup-$DATE
LOGLOC="$LOC.log"
/usr/bin/innobackupex --user=$SQLUSER --password=$SQLPASSWORD --no-timestamp $LOC &>>$LOGLOC
if [ $? -ne 0 ]
then
CONTENT="Backup Failed. Log information below.\n\n--------------------------------------------------------\n$CONTENT"
CONTENT+=`cat $LOGLOC`
echo -e "$CONTENT" | mail -s "Backup on DB3 failed" [email protected]
exit 1
fi
Here's the crontab entry in root's crontab:
5 1 * * * /usr/local/sbin/dbBackup.sh
And the resulting directories/files. Not that on 1/28 I ran it manually, then on 1/29 it was run by cron:
drwxr-xr-x 5 root root 4096 Jan 28 10:18 dbBackup-2015-01-28-1010
-rw-r--r-- 1 root root 21441 Jan 28 10:18 dbBackup-2015-01-28-1010.log
drwxr-xr-x 5 root root 4096 Jan 29 01:14 dbBackup-2015-01-29-0105
-rw-r--r-- 1 root root 0 Jan 29 01:05 dbBackup-2015-01-29-0105.log
I've asked the Googles, but haven't had any luck identifying the problem. Any help would be appreciated.