Mongodb自动备份脚本

来源:互联网 发布:jmeter数据库查询结果 编辑:程序博客网 时间:2024/06/08 11:52

Mongodb自动备份脚本

备份

#!/bin/bashsourcepath='/data/mongo/mongodb'/bintargetpath='/data/mongo/mongobackups'nowtime=$(date +%Y%m%d)start(){  ${sourcepath}/mongodump -h 127.0.0.1:32762 -d test -o ${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} =============="

删除30天之前的备份

#!/bin/bashtargetpath='/data/mongo/mongobackups'nowtime=$(date -d '-30 days' "+%Y%m%d")if [ -d "${targetpath}/${nowtime}/" ]then  rm -rf "${targetpath}/${nowtime}/"  echo "=======${targetpath}/${nowtime}/===?~H| ?~Y??~L?~U=="fiecho "===$nowtime ==="

创建定时任务

服务器的时间要同步,同步的方法微软公司授时主机(美国)     time.windows.com台警大授时中心(台湾)        asia.pool.ntp.org中科院授时中心(西安)        210.72.145.44网通授时中心(北京)           219.158.14.130调用同步:  ntpdate asia.pool.ntp.org权限:chmod 777 filecrontab -e10 04 * * * /data/shell/mongobak 1>/data/log/crontab_mongo_back.file &10 02 * * * /shell/mongobakdelete 1>/data/log/crontab_mongo_delete.file &
原创粉丝点击