Esempio n. 1
0
def cloneDB(conn, myip, myport, clone_db, ip):
    dbList = conn.database_names()
    if len(dbList) == 0:
        printErrMsg('[Error] couldn\'t get a list of databases to clone.')
    elif clone_db in dbList:
        try:
            dbNeedCreds = getQuesMsg(
                '[*] Does this Database require credentials.(y/n)?')
            myDBconn = MongoClient(myip, myport)
            if dbNeedCreds in TAG_NO:
                myDBconn.copyDatabase(clone_db, clone_db + '_clone', ip)
            elif dbNeedCreds in TAG_YES:
                user = getQuesMsg('Username: '******'Password: '******'clone', ip, user,
                                      pwd)
            else:
                getQuesMsg('[*] Invalid Selection. Press enter to continue!')
                cloneDB(conn, myip, myport, clone_db, ip)
        except Exception, e:
            if str(e).find('Connection refused'):
                printErrMsg(
                    '[Error] %s. Make sure that mongoDB has been installed or that mongoDB is opened on this computer.'
                    % e)
            elif str(e).find('text search not enabled'):
                printErrMsg(
                    '[Error] %s. Database copied, but text indexing was not enabled on the target.'
                    % e)
            else:
                printErrMsg('[Error] %s. Something went wrong.' % e)