MySQL转储CronJob [英] MySQL dump CronJob
问题描述
我正在尝试创建一个cron,以每天备份我的MySQL从站。 backup.sh内容:
I'm trying to create a cron that daily backups my MySQL slave. The backup.sh content:
#!/bin/bash
#
# Backup mysql from slave
#
#
sudo mysql -u root -p'xxxxx' -e 'STOP SLAVE SQL_THREAD;'
sudo mysqldump -u root -p'xxxxx' ng_player | gzip > database_`date +\%Y-\%m-\%d`.sql.gz
sudo mysqladmin -u root -p'xxxxx' start-slave
我通过 sudo chmod + x /home/dev/backup.sh
使其可执行。 b $ b,然后通过以下方式输入 crontab
:
I made it executable by sudo chmod +x /home/dev/backup.sh
and entered in to crontab
by:
sudo crontab -e
0 12 * * * /home/dev/backup.sh
但它不起作用,如果我仅在命令行中运行,但它在 crontab
中不起作用。
but it doesn't work, if I only run in the command line it works but not in crontab
.
已修复:
我使用了以下链接中的脚本: mysqldump不会不能在crontab中工作
推荐答案
将问题缩小一半。首先,尝试仅发送来自cron作业的电子邮件,以查看它是否可以正常运行。将其放在文件中,然后将您的cron作业指向该文件:
Break the problem in half. First try sending only email from the cron job to see if you are getting it to even run. Put this above in a file and have your cron job point to it:
#!/bin/bash
/bin/mail -s "test subject" "yourname@yourdomain" < /dev/null
使用此测试仪的好处是它非常简单,并且更有可能给你一些结果。它不取决于您当前的工作目录,有时可能不是您期望的那样。
The good thing about using this tester is that it is very simple and more likely to give you some results. It does not depend on your current working directory, which can sometimes be not what you expect it to be.
这篇关于MySQL转储CronJob的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!