Mongodb定时备份脚本和清除脚本
2013-06-21 17:41
477 查看
Mongodb用的是可以热备份的mongodump和对应恢复的mongorestore,在linux下面使用shell脚本写的定时备份,代码如下
1.定时备份
2.定时清除,保留7天的纪录
3.服务器的时间要同步,同步的方法
微软公司授时主机(美国) time.windows.com
台警大授时中心(台湾) asia.pool.ntp.org
中科院授时中心(西安) 210.72.145.44
网通授时中心(北京) 219.158.14.130
调用同步: ntpdate asia.pool.ntp.org
4.设置上面脚本权限和定时任务
权限:chmod 777 file
定时任务:crontab -e
每天凌晨4点10开始进行备份, 2点10分删除旧的备份
1.定时备份
#!/bin/bash sourcepath='/app/mongodb-linux-x86_64-2.4.1'/bin targetpath='/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} fi execute echo "============== back end ${nowtime} =============="
2.定时清除,保留7天的纪录
#!/bin/bash targetpath='/backup/mongobak' nowtime=$(date -d '-7 days' "+%Y%m%d") if [ -d "${targetpath}/${nowtime}/" ] then rm -rf "${targetpath}/${nowtime}/" echo "=======${targetpath}/${nowtime}/===删除完毕==" fi echo "===$nowtime ==="
3.服务器的时间要同步,同步的方法
微软公司授时主机(美国) time.windows.com
台警大授时中心(台湾) asia.pool.ntp.org
中科院授时中心(西安) 210.72.145.44
网通授时中心(北京) 219.158.14.130
调用同步: ntpdate asia.pool.ntp.org
4.设置上面脚本权限和定时任务
权限:chmod 777 file
定时任务:crontab -e
10 04 * * * /shell/mongobak 1>/log/crontab_mongo_back.file & 10 02 * * * /shell/mongobakdelete 1>/log/crontab_mongo_delete.file &
每天凌晨4点10开始进行备份, 2点10分删除旧的备份
相关文章推荐
- Mongodb定时备份脚本和清除脚本
- Mongodb定时备份脚本和清除脚本
- Shell脚本定时备份清除运行系统日志的代码
- Shell脚本定时备份清除运行系统日志的代码
- Windows中添加Mongodb定时备份任务(采用bat脚本导入xml计划任务的方式)
- Linux-crontab定时执行sh脚本进行数据库备份
- 用Python实现定时备份Mongodb数据,并上传到FTP服务器
- Linux 怎么通过shell脚本定时备份mysql数据库
- SQL Server远程定时备份数据库脚本分享
- Windows下自动备份MongoDB的批处理脚本
- Linux 建立php脚本定时任务 和定时备份数据库
- RMAN定时备份脚本(全备+增量备份+控制文件+参数文件)
- 一个Linux下Mysql备份脚本,可用于crontab定时任务
- 定时备份oracle数据库脚本文件
- debian mysql 定时自动备份的脚本
- mysql定时备份脚本
- 操作4 mongodb备份脚本
- mysql 定时备份bat脚本 ,方便小型服务简单快速备份mysql