shell定时备份mongo

作者: 敲代码的麦兜 | 来源:发表于2017-03-23 14:45 被阅读25次

在服务器上用shell语言+crontab完成对mongo库的定时备份和清除

1. /www/tools/目录下的mongo.sh(备份功能)

#!/bin/bash

targetpath="/data/backup/mongo/"

nowtime=$(date +%y%m%d)

start()

{

mongodump -h (mongo库的地址) -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} =============="

2.  /www/tools/目录下的delmongo.sh(清除功能)

#!/bin/bash

targetpath='/data/backup/mongo/'

nowtime=$(date -d '-3 days' "+%y%m%d")

if [ -d "${targetpath}/${nowtime}/" ]

then

rm -rf "${targetpath}/${nowtime}/"

echo "=======${targetpath}/${nowtime}/===删除完毕=="

fi

echo "===$nowtime ==="

3. 添加crontab

20 1 * * * cd /www/tools;/bin/bash /www/tools/mongo.sh

20 1 * * * cd /www/tools;/bin/bash /www/tools/delmongo.sh

相关文章

  • shell定时备份mongo

    在服务器上用shell语言+crontab完成对mongo库的定时备份和清除 1. /www/tools/目录下的...

  • shell定时备份mysql

    在服务器上用shell定时备份mysql 1. 在crontab中加入定时备份任务 20 1 * * * cd /...

  • Linux Crontab定时任务

    使用Crontab来添加定时任务执行shell文件: shell文件有数据库备份命令. 一. Crontab 介...

  • mysql全量备份数据

    导读:本文介绍的是mysql数据备份恢复的相关知识,以及通过shell编写备份脚本定时执行! 1、mysql数据备...

  • 2. Mongo Shell

    1. Mongo shell 简介 Mongo shell 是与MongoDB进行交互的 JavaScript接口...

  • mysql定时备份单个或多个数据库

    参考1:MySQL定时备份数据库(全库备份) 参考网站中的备份多个数据库的话,需要启动使用多个shell脚本文件...

  • MongoDB 条件查询 --- 2022-04-03

    本章通过mongo shell介绍,MongoDB的基本查询语法,mongo shell中提了db.collect...

  • Mongo Shell交互式命令窗口 --- 2022-04-0

    mongo shell是MongoDB的交互式命令窗口。可以使用mongo shell操作MongoDB,例如:对...

  • 数据库定时备份

    数据库定时备份,围绕两样东西展开,一个是shell程序(一般别人更愿意叫shell脚本),一个是定时任务(cron...

  • Python——MongoDB操作

    pymogo shell连接mongodb的命令mongo 连接mongo 默认连接本地mongo 参数形式连接m...

网友评论

本文标题:shell定时备份mongo

本文链接:https://www.haomeiwen.com/subject/btnznttx.html