Does mongodump lock the database?

后端 未结 2 1868
孤独总比滥情好
孤独总比滥情好 2021-02-07 16:39

I\'m in the middle of setting up a backup strategy for mongo, was just curious to know if mongodump locks the database before performing the database dump?

相关标签:
2条回答
  • 2021-02-07 17:02

    I found this on mongo's google group:

    Mongodump does a simple query on the live system and does not require a shutdown. Like all queries it requires a read lock while running but doesn't not block any more than normal queries.

    If you have a replica set you will probably want to use the --oplog flag to do your backups.

    See the docs for more information

    • http://docs.mongodb.org/manual/administration/backups/

    Additionally I found this previously asked question

    • MongoDB: mongodump/restore vs. backup up files directly

    Excerpt from above question

    Locking and copying files is only an option when you don't have heavy write load.

    mongodump can be run against live server. It will create some additional load, so don't do it on peak hours. Also, it is advised to do it on a secondary node (if you don't use replica sets, you should).

    There are some complications when you have a DB so large that no single machine can hold it. See this document.

    Also, if you have replica set, you take down one of secondaries and copy its files directly. See http://www.mongodb.org/display/DOCS/Backups:

    0 讨论(0)
  • 2021-02-07 17:18

    Mongdump does not lock the db. It means other read and write operations will continue normally.

    Actually, both mongodump and mongorestore are non-blocking. So if you want to mongodump mongorestore a db then its your responsibility to make sure that it is really a desired snapshot backup/restore. To do this, you must stop all other write operations while taking/restoring backups with mongodump/mongorestore. If you are running a sharded environment then its recommended you stop the balancer also.

    0 讨论(0)
提交回复
热议问题