1

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.

fishcracker
  • 181
  • 1
  • 2
  • 6
  • What's in your log files? – David W May 17 '13 at 02:43
  • @DavidW - see my edit please, thanks. I list the last two lines on my log. – fishcracker May 17 '13 at 02: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 Answers2

0

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.

Luis
  • 273
  • 5
  • 9
0

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

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

cuonglm
  • 2,346
  • 2
  • 15
  • 20