Creating a cron job for mysqldump

I am trying to create a cron job to back up a database.

This is what I still have:

mysqldump.sh

 mysqldump -u root -ptest --all-databases | gzip > "/db-backup/backup/backup-$(date)" 2> dump.log

 echo "Finished mysqldump $(date)" >> dump.log

Cron task:

 32 18 * * * /db-backup/mysqldump.sh

The problem that I encountered is that the task is not executed via cron or when I am not in the directory.

Can someone consult. Are my ways wrong?

In addition, the following line, which I'm not sure, will throw errors in dump.log:

 mysqldump -u root -ptest --all-databases | gzip > "/db-backup/backup/backup-$(date)" 2> dump.log

What worked:

 mysqldump -u root -ptest --all-databases | gzip > "../db-backup/backup/backup-$(date).sql.gz" 2> ../db-backup/dump.log

 echo "Finished mysqldump $(date)" >> ../db-backup/dump.log
+5
source share
1 answer

There are a few things you can check, although more information is always more useful (file permissions and location, full file contents, etc.).

  • mysqldump.sh Shebang . , #!/bin/bash .
  • mysqldump -u .... /usr/bin/mysqldump ( ). , , , .

dump.log, , . , gzip dump.log, mysqldump. , mysqldump $PARAMS | gzip -c dump-$(date)

+6

All Articles