AI エージェント向け: ドキュメントインデックスは https://www.mongodb.com/ja-jp/docs/llms.txt で利用できます。すべてのページの markdown バージョンは、いずれかの URL パスに .md を追加することで利用できます。
See how MongoDB 9.0 delivers up to 2x higher throughput.
MongoDB Branding Shape
Register now >
Docs Menu

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

重要

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

注意

この機能はM10 以上のクラスターで使用できます。無料クラスターで使用できる機能の詳細については、「 Atlas 無料クラスターの制限 」を参照してください。Flex クラスターの場合は、「 Atlas Flex 制限 」を参照してください。

と を使用して、S3mongoimport 、 Azuremongorestore 、または Google Cloud Storage にアーカイブされたデータを復元できます。このページでは、 azopygcloudデータソースとMongoDB Database Toolsに応じてAWS 、 、または CLI を使用して、アーカイブ データをインポートし、インデックスを再構築するためのサンプル手順を示します。

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

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

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

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

<bucketName>

AWS S3 バケットの名前。

<prefix>

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

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

<downloadFolder>

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

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

例

aws s3 cp
s3://export-test-bucket/exported_snapshots/1ab2cdef3a5e5a6c3bd12de4/12ab3456c7d89d786feba4e7/myCluster/2021-04-24T0013/1619224539
mybucket --recursive
gunzip -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 mongoimport
find $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 json
done
# 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 mongorestore
find $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.json
done
mongorestore "$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 import
rm -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>"
1
azcopy copy "https://<storageAccountName>.blob.core.windows.net/<containerName>/<prefix>/*" "<downloadFolder>" --recursive

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

<storageAccountName>

BLOBストレージコンテナが属するAzureアカウントの名前。

<containerName>

Azure BLOBストレージコンテナの名前。

<prefix>

バケット内のアーカイブ データへのパス。

<downloadFolder>

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

例

azcopy copy "https://mystorageaccount.blob.core.windows.net/mycontainer/myTextFile.txt" "~/downloads" --recursive
2
#!/bin/bash
regex='/(.+)/(.+)/.+'
dir=${1%/}
connstr=$2
# iterate through the subdirectories of the downloaded and
# extracted snapshot export and restore the docs with mongoimport
find $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 json
done
# 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 mongorestore
find $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.json
done
mongorestore "$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 import
rm -rf ${dir}/metadata/

以下の説明では、

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

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

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

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

<downloadFolder>

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

<connectionString>

stringクラスターの接続Atlas 。

例

sh massimport.sh "~/downloads" "mongodb+srv://<myConnString>"
1
gsutil -m cp -r "gs://<bucketName>/<prefix> <downloadFolder>" --recursive
gunzip -r <downloadFolder>

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

<bucketName>

Google Cloud Platformバケットの名前。

<prefix>

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

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

<downloadFolder>

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

例

gsutil -m cp -r
gs://export-test-bucket/exported_snapshots/1ab2cdef3a5e5a6c3bd12de4/12ab3456c7d89d786feba4e7/myCluster/2021-04-24T0013/1619224539
mybucket --recursive
gunzip -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 mongoimport
find $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 json
done
# 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 mongorestore
find $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.json
done
mongorestore "$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 import
rm -rf ${dir}/metadata/

以下の説明では、

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

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

3

アーカイブ データを Atlas クラスターにインポートするには、 massimport.shユーティリティを実行します。

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

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

<downloadFolder>

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

<connectionString>

stringクラスターの接続Atlas 。

例

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

項目一覧