[MongoDB] バックアップ mongodump とリストア mongorestore

MongoDB のバックアップ mongodump とリストア mongorestore の方法をご紹介します。

MongoDB | モンゴディービー

mongodump でバックアップ

localhost の test_db をバックアップする。

mongodump --host localhost --db test_db

localhost の test_db にある test_collection をバックアップする。

mongodump --host localhost --db test_db --collection test_collection

mongorestore でリストア

バックアップした test_db を全てリストアする。

mongorestore --host localhost --db test_db ./dump/test_db

バックアップした test_db の test_collection をリストアする。

mongorestore --host localhost --db test_db --collection test_collection  ./dump/test_db/test_collection.bson

以上です。