0

I am trying to backup my mysql database using linux crontab like below command,

$crontab -e
15 * * * * /usr/bin/mysqldump -u XXX-pXXX demobackupDB > /home/user/DBbackup/$(date +%F)_backup.sql

But i dont find that .sql file in the specific folder after every 15 mins.

How to find what is error and fix it?

5
  • can you check in error log? Commented Oct 23, 2015 at 10:26
  • @bluto which error log? where it is? Commented Oct 23, 2015 at 10:30
  • which server you are using? Commented Oct 23, 2015 at 10:35
  • then you can check errors in: /var/log/apache2/ error.log file Commented Oct 23, 2015 at 10:37
  • @bluto I checked there but there s nothing error about cron. Commented Oct 23, 2015 at 11:37

2 Answers 2

2

You have wrong crontab. What you specified is "run task at 15 minutes after each hour".

You need this crontab to run task every 15 minutes:

*/15 * * * * /usr/bin/mysqldump -u XXX-pXXX demobackupDB > /home/user/DBbackup/$(date +%F)_backup.sql

If your job is still not running there could be many reasons of this.

You can start debugging with the simple test like this:

* * * * * echo hi >> /home/user/test

(You should see a new line "hi" appended to /home/user/test file once a minute)

If this is not the case see probable reasons for ubuntu here: https://askubuntu.com/q/23009.
Also see cron log: https://askubuntu.com/q/56683/103599

Sign up to request clarification or add additional context in comments.

7 Comments

I tried this too but i dont find .sql file in the DBbackup folder.
Have you tried to run mysqldump command manually in shell? (without crontab)
No i didnt. How to do that?
I mean that you can run this command (/usr/bin/mysqldump -u XXX-pXXX demobackupDB > /home/user/DBbackup/$(date +%F)_backup.sql) directly in bash to see if there is any problem with it and debug it without involving cron.
If i execute the command in root user its created .sql file in the specific folder but if i run the command in sudo user then it says permission denied.
|
0

You can create a file with your statement and make it executable

echo '/usr/bin/mysqldump -u XXX-pXXX demobackupDB > /home/user/DBbackup/$(date +%F)_backup.sql' > backupjob

Make them executable

chmod +x backupjob

And run it

sudo ./backupjob

If everything is fine, the mysql-backup-file should be created. If not, go on with debugging your statement else change your cronjob entry:

cronjob -e

# My MySQL-Backup-Job
*/15 * * * * /yourpath/backup
...

Important: The Crontab-Table must end with an empty line!

For further Informations: Ubuntu - Cron

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.