Mongodb自动备份脚本

Mongodb自动备份脚本

备份

#!/bin/bash
sourcepath='/data/mongo/mongodb'/bin
targetpath='/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}
fi
execute
echo "============== back end ${nowtime} =============="

删除30天之前的备份

#!/bin/bash
targetpath='/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=="
fi
echo "===$nowtime ==="

创建定时任务

服务器的时间要同步,同步的方法
微软公司授时主机(美国)     time.windows.com
台警大授时中心(台湾)        asia.pool.ntp.org
中科院授时中心(西安)        210.72.145.44
网通授时中心(北京)           219.158.14.130
调用同步:  ntpdate asia.pool.ntp.org
权限:chmod 777 file
crontab -e
10 04 * * * /data/shell/mongobak 1>/data/log/crontab_mongo_back.file &
10 02 * * * /shell/mongobakdelete 1>/data/log/crontab_mongo_delete.file &
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值