linux下每天定时备份mongo
来源:互联网 发布:初学者买哪款单片机好 编辑:程序博客网 时间:2024/06/07 10:18
linux下每天定时备份mongo,经过了一番折腾终于完成了
- 写shell脚本
1.1 定时备份
#!/bin/bashsourcepath='/app/mongodb-linux-x86_64-2.4.1'/bintargetpath='/backup/mongobak'nowtime=$(date +%Y%m%d) start(){ ${sourcepath}/mongodump --host 127.0.0.1 --port 27017 --out ${targetpath}/${nowtime}}execute(){ start if [ $? -eq 0 ] then echo "back successfully!" else echo "back failure!" fi} if [ ! -d "${targetpath}/${nowtime}/" ]then mkdir ${targetpath}/${nowtime}fiexecuteecho "============== back end ${nowtime} =============="1.2 定时清除,保留7天的纪录
#!/bin/bashtargetpath='/backup/mongobak'nowtime=$(date -d '-7 days' "+%Y%m%d")if [ -d "${targetpath}/${nowtime}/" ]then rm -rf "${targetpath}/${nowtime}/" echo "=======${targetpath}/${nowtime}/===删除完毕=="fiecho "===$nowtime ==="
以上代码参考:http://www.cnblogs.com/tangnie/p/3148782.html
写完以上shell,
对shell赋权(chmod +x mongobak.sh),
准备执行时,遇到了错误:
syntax error near unexpected token '
我很想跟踪下,看看shell执行的每一步都有什么结果,但不太懂shell,于是乎baidu,
还真找到一篇文章,顿时兴奋了,
http://jingyan.baidu.com/article/9f63fb91d014b8c8410f0e7a.html
看了上面的文章,觉得notepad++,居然还有这作用,点赞!!!
至此,shell的编写和执行完成了,工作完成了60%。
2. 写crontab表达式
2.1 执行crontab -e
2.2 按i键,进入编辑模式。
写表达式
10 04 * * * /shell/mongobak 1>/log/crontab_mongo_back.file &10 02 * * * /shell/mongobakdelete 1>/log/crontab_mongo_delete.file &
写完后,却不知如何保存并退出了,凭着以前的经验,
按了下ctrl+c,果然退出了编辑模式,又baidu,
http://www.linuxidc.com/Linux/2011-05/35644.htm
参考上面的文章,
又按了 :x,保存并退出了crontab !!!
涉及到的知识很多啊,一波好几折。
0 0
- linux下每天定时备份mongo
- linux每天定时备份mysql
- linux下实现mysql数据库每天自动定时备份
- linux下如何实现mysql数据库每天自动备份定时备份
- linux下如何实现mysql数据库每天自动备份定时备份
- linux下如何实现mysql数据库每天自动备份定时备份
- linux下如何实现mysql数据库每天自动备份定时备份
- linux下如何实现mysql数据库每天自动备份定时备份
- linux下如何实现mysql数据库每天自动备份定时备份
- linux下如何实现mysql数据库每天自动备份定时备份
- linux下如何实现mysql数据库每天自动备份定时备份
- linux下如何实现mysql数据库每天自动备份定时备份
- linux下如何实现mysql数据库每天自动备份定时备份
- linux下如何实现mysql数据库每天自动备份定时备份
- linux下如何实现mysql数据库每天自动备份定时备份
- linux下使用crontab如何实现mysql数据库每天自动备份定时备份
- linux下如何实现mysql数据库每天自动备份定时备份
- linux下如何实现mysql数据库每天自动备份定时备份
- 深夜的独白
- sde最大连接数调整
- dsp EMIF接口
- Jquery 常用用法
- 正则总结
- linux下每天定时备份mongo
- android点击按钮调转到指定Fragment并指定activity方法
- word中如何批量修改替换超链接路径地址?
- 人过河 问题
- SD卡与fatfs文件系统(5)-在fatfs中使用多个SD卡分区
- stm8用ST-Link下载时出现Connection error
- 我的不过范德萨就好过放电
- fprintf和fwrite的区别
- 【LeetCode】Evaluate Reverse Polish Notation