开发者

Issue with mysql backup in cron

开发者 https://www.devze.com 2023-02-02 08:24 出处:网络
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:

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 sim开发者_StackOverflow中文版ple comand like "ls" and the output to the same directory and it worked fine.

Any ideas?

Thanks, Aaron


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消