zoukankan      html  css  js  c++  java
  • mongodb 全量备份和恢复

    ./mongodump --host 127.0.0.1 --port 27017 -d test_database --out /usr/mongodb/backup
    ./mongorestore --host 127.0.0.1 --port 27017 -d test_database /usr/mongodb/backup/test_database

     带权限的

    ./mongorestore --host 127.0.0.1 --port 27017 -u root -p root --authenticationDatabase database /usr/mongodb/backup/test_database

    PS:Linux上shell写的定时备份脚步

    转自:http://blog.csdn.net/yuan882696yan/article/details/41523339

           http://www.cnblogs.com/tangnie/p/3148782.html

    #!/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} =============="
    

     定时清除,保留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 ==="
    

    写完以上shell,

    对shell赋权(chmod +x mongobak.sh)

    准备执行时,遇到了错误:

    syntax error near unexpected token '

    http://jingyan.baidu.com/article/9f63fb91d014b8c8410f0e7a.html

    crontab -e

    10 04 * * * /shell/mongobak 1>/log/crontab_mongo_back.file &
    10 02 * * * /shell/mongobakdelete 1>/log/crontab_mongo_delete.file &
    
  • 相关阅读:
    [转载]memcached完全剖析--1. memcached的基础
    I/O多路复用
    How to install the zsh shell in Linux && how to set it as a default login shell
    深入理解计算机中的 csapp.h和csapp.c
    (一)网络编程基础之套接字入门
    crx
    t
    武汉第一例肺炎病例
    C语言 ## __VA_ARGS__ 宏
    NLP之中文分词cppjieba
  • 原文地址:https://www.cnblogs.com/zxcgy/p/8404048.html
Copyright © 2011-2022 走看看