Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Backup database use crontab with date function [duplicate]

I can use this command

mysqldump -u"root"  myDB| gzip > mydb_`date +%d-%m-%Y`.sql.gz

but when run in crontab

* * * * * mysqldump -u"root"  myDB| gzip > mydb_`date +%d-%m-%Y`.sql.gz

( this error cause by function date, when i remove it , crontab run good )

on ubuntu, it happen this error in log file.

ubuntu CRON[xxxx] (user) CMD(mysqldump -u"root"  myDB| gzip > mydb_`date+)
ubuntu CRON[xxxx] (CRON) error ( grandchild #5353 failed with exit status 2)
ubuntu CRON[xxxx] (CRON) info (no MTA installed, discarding output)
like image 451
meotimdihia Avatar asked Aug 27 '11 02:08

meotimdihia


1 Answers

% signs in a crontab command are converted to newlines, and all data after the first % is sent to the command's stdin. Replace each % with \%.

(And you only had 4 time fields: * * * *; you need 5 (you later fixed the question).)

like image 70
Keith Thompson Avatar answered Oct 11 '22 22:10

Keith Thompson