참고
이 기능 무료 클러스터 및 Flex 클러스터에서는 사용할 수 없습니다. 사용할 수 없는 기능에 대해 자세히 학습하려면 Atlas 무료 클러스터 제한을 참조하세요.
및 를 사용하여 mongoimport S,3 Azure mongorestore 또는 Google Cloud Storage에 보관된 데이터를 복원 할 수 있습니다. 이 페이지에서는 azopy gcloud 데이터 소스 및 MongoDB 데이터베이스 도구 에 따라 AWS, 또는 CLI 사용하여 보관된 데이터를 가져오고 인덱스를 다시 작성하는 샘플 절차를 설명합니다.
이미 가져온 클라우드 백업 스냅샷을 가져오기 전에 클라우드 객체 저장소 버킷으로 내보내는 방법을 알아보려면 클라우드 백업 스냅샷을 객체 저장소로 내보내기를 참조하십시오.
전제 조건
시작하기 전에 반드시 해야 할 것은 다음과 같습니다.
- mongoimport 및 mongorestore 도구 설치
절차
AWS CLI 사용하여 S3 버킷의 데이터를 폴더로 복사하고 데이터를 추출합니다.
aws s3 cp s3://<bucketName>/<prefix> <downloadFolder> --recursive gunzip -r <downloadFolder>
where:
| AWS 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아카이브에서 중복 문서를 처리하다 수 있도록 합니다.--uriAtlas 클러스터에 대한 연결 문자열을 지정합니다.
azcopy CLI 사용하여 Azure Blob Storage 컨테이너에 데이터를 복사하고 데이터를 추출합니다.
azcopy copy "https://<storageAccountName>.blob.core.windows.net/<containerName>/<prefix>/*" "<downloadFolder>" --recursive
where:
| 블롭 저장 컨테이너 속한 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아카이브에서 중복 문서를 처리하다 수 있도록 합니다.--uriAtlas 클러스터에 대한 연결 문자열을 지정합니다.
gcloud CLI 를 사용하여 Google Cloud 저장 버킷의 데이터를 복사하고 데이터를 추출합니다.
gsutil -m cp -r "gs://<bucketName>/<prefix> <downloadFolder>" --recursive gunzip -r <downloadFolder>
where:
| 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아카이브에서 중복 문서를 처리하다 수 있도록 합니다.--uriAtlas 클러스터에 대한 연결 문자열을 지정합니다.
massimport.sh 유틸리티를 실행하여 보관된 데이터를 Atlas 클러스터로 가져옵니다.
sh massimport.sh <downloadFolder> "mongodb+srv://<connectionString>"
where:
| 보관된 데이터를 복사한 로컬 폴더의 경로입니다. |
| Atlas 클러스터의 연결 문자열. |
예시
sh massimport.sh mybucket "mongodb+srv://<myConnString>"