【Linux】【MongoDB】 MongoDBでのバックアップとリストアについて

mongodump/mongorestoreコマンドを用いてMongoDBをバックアップとリストアする。

・localhostのtest_dbをバックアップする
mongodump --host localhost --db test_db

・localhostのtest_dbにあるtest_collectionをバックアップする
mongodump --host localhost --db test_db --collection test_collection

・localhostのtest_dbにあるtest_collectionのユーザ”akio”をクエリ指定してバックアップする
mongodump --host localhost --db test_db --collection test_collection -q {userName : 'akio'}

・バックアップした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