0

I'm just trying to perform a mysqldump and have it scheduled. I'm using RHEL 5 and have added it to the crontab as shown below:

22 13 * * * root mysqldump --user=root --password=12345 mysqldb > /var/backups/mysqldbdate +%d%m.sql

The .sql file never ended up in the backups folder. I even attempted to run this command line and it worked fine which tells me its something to do with the cron. Furthermore, I added a simple comand like "ls" and the output to the same directory and it worked fine.

Any ideas?

Thanks, Aaron

Aaron
  • 2,672
  • 10
  • 28
  • 45

2 Answers2

1

I have done this once but I was more like

22 13 * * * mysqldump -u root -p12345 mysqldb >> /var/backups/mysqldb$(date +"%d%m").sql

there is no root before mysqldump. But I am no expert.

BTW, I hope you expect it to run every day at 10:13PM


I have tested the above command does not work. I suggest you to do this:

  1. create a dbbkp.sh (I've saved this file in /home/naishe)
  2. write down the following script, in this shell file

    mysqldump -u root -pmy_password mysqldb > /home/naishe/mybackup$(date +"%d%m").sql
    
  3. chmod a+x dbbkp.sh

  4. Now add this in cronTab

    51 9 * * * /home/naishe/dbbkp.sh
    

I have tested it. It works.

Nishant
  • 54,584
  • 13
  • 112
  • 127
  • thanks for the response. i actually tried it without the root as well and didn't seem to make any difference. yes, i only chose 10:13pm as this was the last time i tested the cron job. – Aaron Jan 02 '11 at 19:55
  • @Aaron You are correct, seems like `date` command is causing issue. I'd suggest go for an independent shell script and call it from Cron. I have updated my answer with the new approach. – Nishant Jan 03 '11 at 04:40
0

I used to support a LAMP server, and we were backuping our databases using this script: http://bash.cyberciti.biz/backup/backup-mysql-database-server-2/ which is linked from this article: http://www.cyberciti.biz/tips/mysql-backup-script.html

It's easy to adapt and works very well! Just call that in your cron job.

Yanick Girouard
  • 4,711
  • 4
  • 19
  • 26