-1

I would like to backup my MySQL database with a cron job, but I cannot make it work.

This is the code that I am using:

0 2 * * * mysqldump -u root toko_db | gzip > /var/backup/toko_db_`date '+%Y-%m-%d'`.sql.gz
matigo
  • 22,138
  • 7
  • 45
  • 75

1 Answers1

0

The date section for the file name seems malformed. Perhaps you could try this:

0 2 * * * mysqldump -u root toko_db | gzip > /var/backup/toko_db_$(date +\%Y-\%m-\%d).sql.gz

Remember to send that file to another location so that you have a recent backup in the event the entire server disappears.

matigo
  • 22,138
  • 7
  • 45
  • 75