Blog Content

    티스토리 뷰

    [MongoDB] copyDatabase

     

    • 속도는 dump 와 비슷하다.
    • 제약사항은 Slave 에는 카피할 수 없다.
    file=`/bin/date '+%Y%m%d'`

    file='fffff'

    createUser="use game_${file};db.createUser({user:\"아이디\",pwd:\"패스워드",roles: [{role:\"readAnyDatabase\",db:\"${file}\"}]})"
    copyCommand="db.copyDatabase("game","game_${file}","192.168.0.1:31001","아이디","패스워드","SCRAM-SHA-1")"


    • copyDatabase 명령어는 복사해오려는 서버에서 실행한다. (to 서버에서 from 서버로 접근해서 끌어오기 방식이다)
    • copyDatabase 작업 시 mongostate 로 crud 가 확인되지 않는다. (dstat 또는 iostat 로 확인)
    • copyDatabase 작업 시 index 설정도 그대로 복사되기 때문에 시간이 장시간 소요된다.

    Parameter
    Type Description
    fromdb string Name of the source database.
    todb string Name of the target database.
    fromhost string Optional. The hostname of the source mongod instance. Omit to copy databases within the same mongod instance.
    username string

    Optional. The name of the user on the fromhost MongoDB instance. The user authenticates to the fromdb.

    For more information, see Authentication to Source mongod Instance.

    password string

    Optional. The password on the fromhost for authentication. The method does not transmit the password in plaintext.

    For more information, see Authentication to Source mongod Instance.

    mechanism string

    Optional. The mechanism to authenticate the username and password on the fromhost. Specify either MONGODB-CR or SCRAM-SHA-1.

    db.copyDatabase defaults to SCRAM-SHA-1 if the wire protocol version (maxWireVersion) is greater than or equal to 3 (i.e. MongoDB versions 3.0 or greater). Otherwise, it defaults to MONGODB-CR.

    Specify MONGODB-CR to authenticate to the version 2.6.x fromhost from a version 3.0 instance or greater. For an example, see Copy Database from a mongod Instances that Enforce Authentication.

    New in version 3.0.

     

    Comments