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

4
  • 1
    Can you find any related items in syslog?
    – Melebius
    May 25, 2017 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, 2017 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, 2017 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, 2017 at 13:09

2 Answers 2

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
2
  • 2
    We do NOT supply the password in plain text. That is a security violation --defaults-extra-file= is the way to go
    – Rinzwind
    Jun 5, 2019 at 14:18
  • Yes we can give it in that way @Rinzwind Thank you
    – dash
    Jun 6, 2019 at 4:20
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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .