AI エージェント向け: ドキュメントインデックスは https://www.mongodb.com/ja-jp/docs/llms.txt で利用できます。すべてのページの markdown バージョンは、いずれかの URL パスに .md を追加することで利用できます。
Docs Menu

データベース ダンプから自己管理型シャーディングされたクラスターを復元する

mongorestore is a tool that reads mongodump binary exports and restores the data to a MongoDB deployment. Use mongorestore to restore a sharded cluster from a mongodump backup.

Ensure you have a mongodump backup of your source cluster. To create one, see Back Up a Self-Managed Sharded Cluster with a Database Dump. If you have file system snapshots, see Restore a Self-Managed Sharded Cluster from Snapshots.

1

チャンクの移行によって復元が中断されないようにするには、 mongos に接続してバランサーを停止します。

sh.stopBalancer()

バランサーが停止したことを確認するには、次のコマンドを実行します。

use config
while( sh.isBalancerRunning().mode != "off" ) {
print( "Waiting for Balancer to stop..." );
sleep( 1000 );
}
2

ソースクラスター内の各シャーディングされたコレクションについては、データを復元する前に対象クラスター上にコレクションを作成し、同じシャードキーを使用してシャードします。

各コレクションのシャードキーを見つけるには、ライブソースクラスターをクエリします。

use config
db.collections.find()

Alternatively, you can use bsondump to inspect the config/collections.bson file from your dump directory:

bsondump /path/to/dump/config/collections.bson
{
"_id": "<database>.<collection>",
...
"key": { "<shardKeyField>": "<key>" },
...
}

注意

有効なシャードキー値は 1 または "hashed" です。

シャーディングされたコレクションごとに、同じシャードキーを使用して対象クラスターでコレクションをシャードします。

sh.shardCollection(
"<database-name>.<collection-name>",
{ <shardKeyField>: <key> }
)
3

Use mongorestore to connect to mongos and restore the cluster. Exclude the config database to preserve the destination cluster's existing configuration:

mongorestore \
--host <host> \
--port 27017 \
--username <username> \
--password "<password>" \
--authenticationDatabase admin \
--nsExclude='config.*' \
/path/to/backup

重要

The --drop option drops the collection before restoring. If you use --drop after pre-sharding collections, mongorestore removes the sharding configuration.

4

復元が完了したら、バランサーを再起動します。

sh.startBalancer()

バランサーが実行中であることを確認するには、

sh.isBalancerRunning().mode
full
5

mongos に接続し、sh.status() を実行してクラスター全体のステータスを確認します。

sh.status()

すべてのシャードがアクセス可能であり、通信していることを確認するため、一時的なコレクションにテスト ドキュメントを挿入します。

db.testRestore.insertOne({ test: 1 })

次に、各シャード プライマリに接続し、db.collection.find() を実行してドキュメントが存在することを確認します。

db.testRestore.find()
このページを評価