Cronjob每天晚上10点备份数据库

我设法设置一个cronjob:

* 13 * * * date=`date +\%d-\%m-\%Y-\%s`; mysqldump -u root -pPassword1 db121 > /home/backup/xbackup_$date.sql; gzip /home/backup/xbackup_$date.sql 

我希望上面的每天晚上10点会有一个mysqldump ,然后保存到/ home / backup目录中。 但是,这并没有为我工作。

上面的条目在crontab中是否正确? 如果是这样,为什么不采取备份,因为命令工作正常,当我自己执行。

感谢所有的帮助

更新

我正在阅读cron作业的centos 手册 ,它说:

root以外的用户可以使用crontab实用程序configurationcron任务。

Surley,这是不正确的?

crontab(5)手册页:

  The "sixth" field (the rest of the line) specifies the command to be run. The entire command portion of the line, up to a newline or % character, will be executed by /bin/sh or by the shell specified in the SHELL variable of the cronfile. Percent-signs (%) in the command, unless escaped with backslash (\), will be changed into newline charac- ters, and all data after the first % will be sent to the command as standard input. 

很可能这些命令不在$PATH ,在crontab中设置或者给出命令的完整path,例如/usr/bin/mysqldump

我会这样做

 date='date +\%d-\%m-\%Y-\%s' 0 22 * * * mysqldump -u root -pPassword1 db121 > /home/backup/xbackup_`$date`.sql; gzip /home/backup/xbackup_`$date`.sql