zoukankan      html  css  js  c++  java
  • 自动备份远程mongodb数据库并拉取到本地

    自动备份远程mongodb数据库并拉取到本地
    
    目标:
    远程服务器 1.1.1.1 中运行mongodb数据库,需要将 1.1.1.1中的mongodb数据拉回公司测试服务器中
    
    1.远程服务器中编写自动备份mongodb脚本
    
    ①编写脚本
    # vim /opt/back_mongo.sh
    #!/bin/bash
    
    today_date=`date "+%Y%m%d"`
    # 创建备份当天日期文件夹
    mkdir $today_date
    # 导出convert_v1_prod库
    /usr/local/mongodb-linux-x86_64-3.4.6/bin/mongodump -h 127.0.0.1 -u hichinasoftUser -p hichinasoft2018 -d convert_v1_prod -o /opt/mongo_back/$today_date/ --authenticationDatabase admin
    # 导出chinasoft_v2_prod
    /usr/local/mongodb-linux-x86_64-3.4.6/bin/mongodump -h 127.0.0.1 -u chinasoftPE -p chinasoftPE2017 -d chinasoft_v2_prod -o /opt/mongo_back/$today_date/ --authenticationDatabase admin
    # 导出
    /usr/local/mongodb-linux-x86_64-3.4.6/bin/mongodump -h 127.0.0.1 -u chinasoftonline -p chinasoftonline2018 -d data_hichinasoft_prod -o /opt/mongo_back/$today_date/ --authenticationDatabase admin
    
    # 赋权,方便rsync进行拉取
    chown -R apache.users /opt/mongo_back
    
    # 删除10天前的文件
    find /opt/mongo_back/ -mtime +10 -exec rm -rf {} ;
    
    
    ②添加计划任务crontab -e
    
    #### backup mongodb every day
    10 05 * * * /bin/bash /opt/back_mongo.sh > /dev/null 2>&1
    
    2.公司本地拉取mongo的备份,4个小时执行一次
    
    # 计划任务
    15,30,45 */4 * * * /bin/bash /opt/mongoback_tolocal.sh >/dev/null 2>&1
    
    [root@localhost 2018-11]# vim /opt/mongoback_tolocal.sh
    #!/bin/bash
    SIP="1.1.1.1"
    
    DATE="`date -d "${a} day" +%Y-%m`"
    # 拉取远程服务器 1.1.1.1 上 的 mongodb的备份 目录到本地
    /usr/bin/rsync -avrp -P --password-file=/data/www/.rsync/rsyncd.pass apache@${SIP}::apache/opt/mongo_back/ /data/mongo_back_local/
    
    find /data/mongo_back_local/ -mtime +10 -exec rm -rf {} ;
  • 相关阅读:
    快速读取txt文档
    ASP.NET中缓存非SQLServer数据库数据
    查看linq to sql 生成的sql 语句
    跟树有关的数据结构学习系列之概览
    Linux安装软件包时的“依赖关系树”算法(C#)
    Go调度器介绍和容易忽视的问题
    搞懂Go垃圾回收
    Go“一个包含nil指针的接口不是nil接口”踩坑
    Go slice:切片的“陷阱”和本质
    C#调用ODBC连接SQL Server数据库的存储过程
  • 原文地址:https://www.cnblogs.com/reblue520/p/10338189.html
Copyright © 2011-2022 走看看