MySQL使用crontab定时备份不执行问题
2024-09-03 13:55:55
在使用crontab定时备份数据库时,发现并没有执行备份命令.
下面是定时备份的代码:
30 1 * * * /usr/local/mysql/bin/mysqldump --defaults-extra-file=/usr/local/mysql/etc/my.cnf yxv9 | gzip > /root/sqldb/yw/ywv9_`date '+%m-%d-%Y'`.sql.gz
但是直接如下面一样执行命令时,,却可以备份.
/usr/local/mysql/bin/mysqldump --defaults-extra-file=/usr/local/mysql/etc/my.cnf yxv9 | gzip > /root/sqldb/yw/ywv9_`date '+%m-%d-%Y'`.sql.gz
这到底怎么回事呢?
通过查看crontab的执行日志竟然发现任务出错了!
/bin/sh: -c: line 0: unexpected EOF while looking for matching ``'
/bin/sh: -c: line 1: syntax error: unexpected end of file
从上面的出错信息可以看到,一个cmd被从中间截断了,脚本在 /bin/date +"
之后就被截断了,出现了语法错误。
原来是让%
闹得.
The "sixth" field (the rest of the line) specifies the command to be run. The entire command portion of the line, up to a new‐line or a "%" character, will be executed by /bin/sh or by the shell specified in the SHELL variable of the cronfile. A "%" character in the command, unless escaped with a backslash (), will be changed into newline characters, and all data after thefirst % will be sent to the command as standard input.
原来是 % 这个符号在crontab里面被翻译成了命令结束,所以当crontab读到%就吧后面的内容截取掉了,导致脚本执行失败。
那么怎么解决呢?
在%前面加上转移符号""即可,如下:
30 1 * * * /usr/local/mysql/bin/mysqldump --defaults-extra-file=/usr/local/mysql/etc/my.cnf yxv9 | gzip > /root/sqldb/yw/ywv9_`date '+\%m-\%d-\%Y'`.sql.gz
最新文章
- [LeetCode] Permutations 全排列
- XidianOJ 1099 A simple problem
- Android Studio线下版和线上版都使用正式签名脚本(保证keysore签名文件和项目在同级目录),不用再因为繁琐的发正式版而烦恼
- java入门(1)
- c_水程序
- 解决ScrollView嵌到listView冲突问题
- 深入理解JS闭包
- Microsoft .NET Framework NGEN是神马东东?
- python __del__
- Dictionary解析json,里面的数组放进list,并绑定到DataGridView指定列
- 服务器判断客户端为移动端还是PC端
- 重新安装Photoshop CS6以后启动软件出现Licensing for this product has expired
- SampleManager(赛默飞)
- 常用的 css reset,基本的base.css
- WPF自学入门(六)WPF带标题的内容控件简单介绍
- 10个Python练手小程序,学习python的很好的资料
- python-----HTMLTestRunner报告生成注意点!
- 记一次SQL性能优化,查询时间从4000ms优化到200ms.
- Quartz_配置
- C#反射实现
热门文章
- clientHeight—scrollHeight—offsetHeight三者的区别
- 【总结】《氨基酸新晋管理者领导力培训》第一次课_Day2_学习心得
- Python中文件操作2——shutil模块
- OpenGL光照1:颜色和基础光照
- FastJson中的ObjectMapper对象的使用详解
- java基础(26):Thread、线程创建、线程池
- CSS字体属性
- [转]JVM系列二:GC策略&;内存申请、对象衰老
- Spring Cloud Netflix Ribbon详细介绍及自定义规则策略
- RAW数据格式解析