0

I have the following script in /etc/cron.daily/, it works perfectly if I execute it manually but never runs via cron. There are other scripts in cron.daily that do execute however.

#!/bin/bash
DATE=`date +%Y%m%d`
FILENAME=mysql_$DATE.tar.gz
DESDIR=/data/mysqlbackup/

echo Deleting backups older than 30 days
echo Files deleted:
find /data/mysqlbackup/ -mtime +30 -type f -ls
find /data/mysqlbackup/ -mtime +30 -type f -delete

echo Backing up all databases
mysqldump -u backup -p --all-databases --events | gzip > $DESDIR$FILENAME

echo Backup complete:
ls -lh $DESDIR

What could the issue be?

I'm running Ubuntu 14.04

  • 1
    Can you find any related items in syslog? – Melebius May 25 '17 at 12:36
  • 1
    Besides syslog: mysql has a log file in /var/log/ too. I would expect there to be a "missing password" notice. – Rinzwind May 25 '17 at 12:39
  • How are you checking whether the script runs? Does it not run or does it maybe run but not work? Add echo foo > /tmp/cron.test at the beginning of the script. Is the file /tmp/cron.test created? Also, how are you running the script? Did you just put it in /etc/cron.daily/ and expect it to run? If so, please [edit] your question and explain that, and tell us the name of your script (the name matters here). – terdon May 25 '17 at 13:09
  • How are you checking whether the script runs? Does it not run or does it maybe run but not work? Add echo foo > /tmp/cron.test at the beginning of the script. Is the file /tmp/cron.test created? Also, how are you running the script? Did you just put it in /etc/cron.daily/ and expect it to run? If so, please [edit] your question and explain that, and tell us the name of your script (the name matters here). – terdon May 25 '17 at 13:09

2 Answers2

0

set Path for mysqldump in bash or shell script like whereis mysqldump and add full path in scrip

/usr/bin/mysqldump -u root -p database > /backuppath/mysqldumpdate.sql
Rinzwind
  • 299,756
0

set Path for mysqldump in your shell script and then add full path in script as below.

For example : in your script

   mysqlpath=/path/to/mysql/instalation/bin

   $mysqlpath/mysqldump -u $USER -p$PASSWORD -h$IP  $DATABASE  > $BACKUP_DIR/$DATABASE.$DATE_STAMP.sql
dash
  • 1