在cron中使用mysql备份的问题 [英] Issue with mysql backup in cron
问题描述
我只是试图执行一个mysqldump并安排它。我使用RHEL 5并将其添加到crontab如下所示:
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 / mysqldb date +%d%m
.sql
22 13 * * * root mysqldump --user=root --password=12345 mysqldb > /var/backups/mysqldbdate +%d%m
.sql
.sql文件在backups文件夹中。我甚至试图运行这个命令行,它工作正常,告诉我它的东西与cron。此外,我添加了一个简单的comand像ls和输出到同一个目录,它工作正常。
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.
有任何想法吗?
感谢,
Aaron
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
在 mysqldump
之前没有根。但我不是专家。
there is no root before mysqldump
. But I am no expert.
BTW,希望您期望它每天在10:13 PM运行
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:
- 创建一个
dbbkp.sh
ve将此文件保存在/ home / naishe
) -
在此shell文件中写下以下脚本
- 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
现在将它添加到cronTab
Now add this in cronTab
51 9 * * * /home/naishe/dbbkp.sh
/ li>
我已经测试过了。它工作。
I have tested it. It works.
这篇关于在cron中使用mysql备份的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!