Issue with mysql backup in cron
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:
- create a
dbbkp.sh
(I've saved this file in/home/naishe
) write down the following script, in this shell file
mysqldump -u root -pmy_password mysqldb > /home/naishe/mybackup$(date +"%d%m").sql
chmod a+x dbbkp.sh
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.
精彩评论