Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

This question already has an answer here:

I am trying to do a mysqldump on the cron for every 5 minutes but it seems that it is not working. I try to execute the mysqldump and it works fine.

mysqldump

mysqldump -uroot -ppassword --single_transaction --opt dbname | gzip > /home/myhome/backup/dbname.`date +"%T"`.sql.gz

cron

*/5 * * * * mysqldump -uroot -ppassword --single_transaction --opt dbname | gzip > /home/myhome/backup/dbname.`date +"%T"`.sql.gz

LOG

May 17 04:35:42 CentOS-63-64-minimal crontab[5605]: (root) LIST (root)
May 17 04:40:01 CentOS-63-64-minimal CROND[5626]: (root) CMD (mysqldump -uroot -ppassword --single_transaction --opt dbname | gzip > /home/myhome/backup/dbname.`date +")

UPDATE

I think I found the problem, it is in date +"%T", because if I replace it with date -I it now works. However, I need to append a date & time on the filename.

share|improve this question

marked as duplicate by Ladadadada, Iain May 19 '13 at 11:45

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
What's in your log files? –  David W May 17 '13 at 2:43
    
@DavidW - see my edit please, thanks. I list the last two lines on my log. –  fishcracker May 17 '13 at 2:45

2 Answers 2

This should be a path problem for the cron entry.

Try to use /usr/bin/mysqldump instead of mysqldump, /usr/bin/gzip instead of gzip only, and /usr/bin/date instead of date. Change the path accordingly to your system. Use command whereis to find the paths for the commands.

share|improve this answer

You should put your command in a script, i.e backupmysql, then add this entry in cron:

*/5 * * * * /path/to/backupmysql

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.