注意
この機能は、 無料クラスターと Flex クラスターでは使用できません。使用できない機能の詳細については、Atlas 無料クラスターの制限 を参照してください。
S3、Azure、または Google Cloud Storage にアーカイブされたデータを復元できます。mongoimport と mongorestore を使用して。このページでは、データソース、および MongoDB Database Tools に応じて、 AWS 、azopy 、またはgcloud CLI を使用して、アーカイブ データをインポートし、インデックスを再構築するためのサンプル手順を示します。
前提条件
始める前に、以下の操作を行う必要があります。
mongoimportとmongorestoreツールをインストールする
手順
AWS CLI を使用して S3 バケット内のデータをフォルダーにコピーし、データを抽出します。
aws s3 cp s3://<bucketName>/<prefix> <downloadFolder> --recursive gunzip -r <downloadFolder>
以下の条件に一致するもの。
| Amazon Web Services S3バケットの名前。 | |
| バケット内のアーカイブ データへのパス。 パスの形式は次のとおりです。 | |
| アーカイブされたデータをコピーするローカル フォルダーへのパス。 |
たとえば、次のようなコマンドを実行します。
例
aws s3 cp s3://export-test-bucket/exported_snapshots/1ab2cdef3a5e5a6c3bd12de4/12ab3456c7d89d786feba4e7/myCluster/2021-04-24T0013/1619224539 mybucket --recursive gunzip -r mybucket
次のスクリプトをコピーして、massimport.sh という名前のファイルに保存します。
!/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はアーカイブから重複ドキュメントを処理できます。--uristringは、Atlas クラスターの 接続 を指定します。
アーカイブ データを Atlas クラスターにインポートするには、massimport.sh ユーティリティを実行します。
sh massimport.sh <downloadFolder> "mongodb+srv://<connectionString>"
以下の条件に一致するもの。
| アーカイブ データをコピーしたローカル フォルダーへのパス。 |
| stringクラスターの接続Atlas 。 |
たとえば、次のようなコマンドを実行します。
例
sh massimport.sh mybucket "mongodb+srv://<myConnString>"
azcopy CLI を使用してAzure Blob ストレージコンテナ内のデータをコピーし、データを抽出します。
azcopy copy "https://<storageAccountName>.blob.core.windows.net/<containerName>/<prefix>/*" "<downloadFolder>" --recursive
以下の条件に一致するもの。
| BLOBストレージコンテナが属するAzureアカウントの名前。 |
| Azure BLOBストレージコンテナの名前。 |
| バケット内のアーカイブ データへのパス。 |
| アーカイブされたデータをコピーするローカル フォルダーへのパス。 |
例
azcopy copy "https://mystorageaccount.blob.core.windows.net/mycontainer/myTextFile.txt" "~/downloads" --recursive
次のスクリプトをコピーして、massimport.sh という名前のファイルに保存します。
!/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はアーカイブから重複ドキュメントを処理できます。--uristringは、Atlas クラスターの 接続 を指定します。
gcloud CLI を使用して Google Cloud ストレージバケット内のデータをコピーし、データを抽出します。
gsutil -m cp -r "gs://<bucketName>/<prefix> <downloadFolder>" --recursive gunzip -r <downloadFolder>
以下の条件に一致するもの。
| Google Cloud Platformバケットの名前。 | |
| バケット内のアーカイブ データへのパス。 パスの形式は次のとおりです。 | |
| アーカイブされたデータをコピーするローカル フォルダーへのパス。 |
例
gsutil -m cp -r gs://export-test-bucket/exported_snapshots/1ab2cdef3a5e5a6c3bd12de4/12ab3456c7d89d786feba4e7/myCluster/2021-04-24T0013/1619224539 mybucket --recursive gunzip -r mybucket
次のスクリプトをコピーして、massimport.sh という名前のファイルに保存します。
!/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はアーカイブから重複ドキュメントを処理できます。--uristringは、Atlas クラスターの 接続 を指定します。
アーカイブ データを Atlas クラスターにインポートするには、 massimport.shユーティリティを実行します。
sh massimport.sh <downloadFolder> "mongodb+srv://<connectionString>"
以下の条件に一致するもの。
| アーカイブ データをコピーしたローカル フォルダーへのパス。 |
| stringクラスターの接続Atlas 。 |
例
sh massimport.sh mybucket "mongodb+srv://<myConnString>"