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

アーカイブされたスナップショットを Atlas にインポートする

重要

このページで説明されている機能は、パブリックプレビュー期間中、Atlas Infiniteクラスターでは現在サポートされていません。パブリックプレビューでサポートされている機能については、パブリックプレビューの可用性を参照してください。

注意

この機能は、M10 クラスター以上で使用できます。Free クラスターで利用可能な機能について学ぶには、「Atlas Free Cluster Limits」を、Flex クラスターについては「Atlas Flex Limitations」を参照してください。

S3、Azure、または Google Cloud Platform ストレージにアーカイブされたデータは、mongoimport と mongorestore を使用して復元できます。このページには、データソースに応じて、Amazon Web Services CLI、azopy CLI、または gcloud CLI および MongoDB Database Tools を使用して、アーカイブされたデータをインポートし、インデックスを再構築するためのサンプル手順が記載されています。

クラウドバックアップスナップショットをインポートする前にクラウドオブジェクトストレージバケットにエクスポートする方法については、「クラウドバックアップスナップショットをオブジェクトストレージにエクスポートする」を参照してください。

始める前に、以下の操作を行う必要があります。

1
aws s3 cp s3://<bucketName>/<prefix> <downloadFolder> --recursivegunzip -r <downloadFolder>

以下の条件に一致するもの。

<bucketName>

AWS S3 バケットの名前。

<prefix>

バケット内のアーカイブ データへのパス。 パスの形式は次のとおりです。

/exported_snapshots/<orgId>/<projectId>/<clusterName>/<initiationDateOfSnapshot>/<timestamp>/

<downloadFolder>

アーカイブされたデータをコピーするローカル フォルダーへのパス。

たとえば、次のようなコマンドを実行します。

例

aws s3 cps3://export-test-bucket/exported_snapshots/1ab2cdef3a5e5a6c3bd12de4/12ab3456c7d89d786feba4e7/myCluster/2021-04-24T0013/1619224539mybucket --recursivegunzip -r mybucket
2
#!/bin/bash regex='/(.+)/(.+)/.+'dir=${1%/}connstr=$2 # iterate through the subdirectories of the downloaded and# extracted snapshot export and restore the docs with mongoimportfind $dir -type f -not -path '*/\.*' -not -path '*metadata\.json' | while read line ; do [[ $line =~ $regex ]] db_name=${BASH_REMATCH[1]} col_name=${BASH_REMATCH[2]} mongoimport --uri "$connstr" --mode=upsert -d $db_name -c $col_name --file $line --type jsondone # create the required directory structure and copy/rename files# as needed for mongorestore to rebuild indexes on the collections# from exported snapshot metadata files and feed them to mongorestorefind $dir -type f -name '*metadata\.json' | while read line ; do [[ $line =~ $regex ]] db_name=${BASH_REMATCH[1]} col_name=${BASH_REMATCH[2]} mkdir -p ${dir}/metadata/${db_name}/ cp $line ${dir}/metadata/${db_name}/${col_name}.metadata.jsondonemongorestore "$connstr" ${dir}/metadata/ # remove the metadata directory because we do not need it anymore and this returns# the snapshot directory in an identical state as it was prior to the importrm -rf ${dir}/metadata/

以下の説明では、

  • --mode=upsert により、 mongoimportはアーカイブから重複ドキュメントを処理できます。

  • --uri stringは、Atlas クラスターの 接続 を指定します。

3
sh massimport.sh <downloadFolder> "mongodb+srv://<connectionString>"

以下の条件に一致するもの。

<downloadFolder>

アーカイブ データをコピーしたローカル フォルダーへのパス。

<connectionString>

stringクラスターの接続Atlas 。

たとえば、次のようなコマンドを実行します。

例

sh massimport.sh mybucket "mongodb+srv://<myConnString>"
このページを評価

項目一覧