重要
このページで説明されている機能は、パブリックプレビュー期間中、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 を使用して、アーカイブされたデータをインポートし、インデックスを再構築するためのサンプル手順が記載されています。
クラウドバックアップスナップショットをインポートする前にクラウドオブジェクトストレージバケットにエクスポートする方法については、「クラウドバックアップスナップショットをオブジェクトストレージにエクスポートする」を参照してください。
前提条件
始める前に、以下の操作を行う必要があります。
- mongoimportとmongorestoreツールをインストールする
手順
AWS CLI を使用して S33 バケット内のデータをフォルダにコピーし、データを抽出します。
aws s3 cp s3://<bucketName>/<prefix> <downloadFolder> --recursivegunzip -r <downloadFolder>以下の条件に一致するもの。
| AWS S3 バケットの名前。 |
| バケット内のアーカイブ データへのパス。 パスの形式は次のとおりです。 |
| アーカイブされたデータをコピーするローカル フォルダーへのパス。 |
たとえば、次のようなコマンドを実行します。
例
aws s3 cps3://export-test-bucket/exported_snapshots/1ab2cdef3a5e5a6c3bd12de4/12ab3456c7d89d786feba4e7/myCluster/2021-04-24T0013/1619224539mybucket --recursivegunzip -r mybucket次のスクリプトをコピーして、massimport.sh という名前のファイルに保存します。
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はアーカイブから重複ドキュメントを処理できます。--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 という名前のファイルに保存します。
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はアーカイブから重複ドキュメントを処理できます。--uristringは、Atlas クラスターの 接続 を指定します。
gcloud CLI を使用して Google Cloud ストレージバケット内のデータをコピーし、データを抽出します。
gsutil -m cp -r "gs://<bucketName>/<prefix> <downloadFolder>" --recursivegunzip -r <downloadFolder>以下の条件に一致するもの。
| Google Cloud Platformバケットの名前。 |
| バケット内のアーカイブ データへのパス。 パスの形式は次のとおりです。 |
| アーカイブされたデータをコピーするローカル フォルダーへのパス。 |
例
gsutil -m cp -rgs://export-test-bucket/exported_snapshots/1ab2cdef3a5e5a6c3bd12de4/12ab3456c7d89d786feba4e7/myCluster/2021-04-24T0013/1619224539mybucket --recursivegunzip -r mybucket次のスクリプトをコピーして、massimport.sh という名前のファイルに保存します。
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はアーカイブから重複ドキュメントを処理できます。--uristringは、Atlas クラスターの 接続 を指定します。
アーカイブ データを Atlas クラスターにインポートするには、 massimport.shユーティリティを実行します。
sh massimport.sh <downloadFolder> "mongodb+srv://<connectionString>"以下の条件に一致するもの。
| アーカイブ データをコピーしたローカル フォルダーへのパス。 |
| stringクラスターの接続Atlas 。 |
例
sh massimport.sh mybucket "mongodb+srv://<myConnString>"