Issue with mysql backup in cron

一世执手 提交于 2019-12-11 17:28:19

问题


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


回答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.




回答2:


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.



来源:https://stackoverflow.com/questions/4565194/issue-with-mysql-backup-in-cron

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!