Cron job doing MySQL database back up not working when append date to the file name

I'm using shared cPanel hosting.

When I enter the following cron job command it works:

*/5 *   *   *   *   /usr/bin/mysqldump -u user -p'pazzword' my_db > /backup/database.sql

But when I try to add date stamp to the file name, it doesn't generate .sql files.

*/5 *   *   *   *   /usr/bin/mysqldump -u user -p'pazzword' my_db > /backup/database_$(date +"%Y_%m_%d").sql

I can't find cron job error logs, have I made an error in my command?

Upvotes: 0

Views: 231

Answers (1)

Okay. Finally I managed to fix the problem.

You need to escape % with **** .

So the working cron job command will look like this:

 */5 *   *   *   *   /usr/bin/mysqldump -u user -p'pazzword' my_db > /backup/database_$(date +"\%Y_\%m_\%d").sql

Upvotes: 0

Related Questions