Take the 2-minute tour ×
Server Fault is a question and answer site for 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 -uroot -ppassword --single_transaction --opt dbname | gzip > /home/myhome/backup/dbname.`date +"%T"`.sql.gz


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


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 +")


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
I had this problem & the 'duplicate' question was not helpful. The solution I found: you need to escape the ampersand. Try this for your filename: dbname.date +\%T.sql.gz (I cannot post this as an answer as this question is marked as a duplicate) –  caitriona Dec 16 '14 at 17:26

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.