zoukankan      html  css  js  c++  java
  • Mongo Restore

    #!/bin/sh
    
    HOST_IP=`/sbin/ifconfig | sed -n 's/.*inet addr:([0-9.]+)s.*/1/p' | head -n1`
    echo "HOST_IP: " $HOST_IP
    
    HOST_NAME=`hostname`
    echo "HOST_NAME: " $HOST_NAME
    
    IS_PRIMARY=`mongo --quiet $HOST_IP --eval "print(db.isMaster().ismaster);"`
    echo "IS_PRIMARY: " $IS_PRIMARY
    
    PRIMARY_HOST=`mongo --quiet $HOST_IP --eval " var primary = db.isMaster().primary;
    if(primary && primary.indexOf(':') > 0 ) primary = primary.substring(0, primary.indexOf(':'));
    print(primary);"`
    echo "PRIMARY_HOST: " $PRIMARY_HOST
    
    if [ "${IS_PRIMARY}" == "true" ]
    then
        echo "$PRIMARY_HOST is primary mongo node. Restoring data...."
        BACKUP_FOLDER=$1
    
        if [ "x$BACKUP_FOLDER" = "x" ]; then
            echo "Missing database dump folder: mongo-db-restore.sh <BKP_FOLDER>"
            exit
        fi
    
        if [ ! -d $BACKUP_FOLDER ]; then
            echo "Database dump folder does not exist: $BACKUP_FOLDER"
            exit
        fi
    
        if [ ! -d $BACKUP_FOLDER/dump ]; then
            echo "Database dump folder does not have sub-folder 'dump'. May not be the correct folder: $BACKUP_FOLDER"
            exit
        fi
        cd $BACKUP_FOLDER
        echo "PWD:" `pwd`
        RESTORE_RESULT=`mongorestore -h $HOST_IP --drop`
        echo "Restore complete."
    
    else
        echo "$HOST_NAME is not primary mongo server ($PRIMARY_HOST is primary). Restore should be run only on the primary."
    fi
  • 相关阅读:
    EasyUI Datagrid换页不清出勾选方法
    【HDOJ】4902 Nice boat
    【HDOJ】1688 Sightseeing
    【HDOJ】3584 Cube
    【POJ】2155 Matrix
    【HDOJ】4109 Instrction Arrangement
    【HDOJ】3592 World Exhibition
    【POJ】2117 Electricity
    【HDOJ】4612 Warm up
    【HDOJ】2888 Check Corners
  • 原文地址:https://www.cnblogs.com/tben/p/8985065.html
Copyright © 2011-2022 走看看