Linux – Cronjob to Backup Database every day at 10pm

bashcronlinuxMySQL

I managed to setup a cronjob:

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

I am hoping the above will take a mysqldump everyday at 10pm and then save into the /home/backup directory. However, this has not worked for me.

Is the above entry correct in the crontab? If so, why wouldn't it take a backup as the command works fine when I execute it myself.

Thanks all for any help

Update

I was reading the centos manual for cron jobs and it says:

Users other than root can configure
cron tasks by using the crontab
utility.

Surley, this isn't true?

Best Answer

From the crontab(5) man page:

   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.
Related Topic