1. DB 또는 Collection 백업하기

mongodump \

  --host={호스트:포트} \

  --readPreference=secondary \

  --username={관리자계정} \

  --password={비밀번호} \

  --authenticationDatabase=admin \

  --db={DB이름} \

  --collection={Collection이름} \

  --query='{DB 쿼리 조건}' \

  --gzip \

  --out={결과가 저장될 경로명}

  --archive={결과가 저장될 파일명}


옵션> --out--archive 옵션은 중복 사용할 수 없음


참고> https://docs.mongodb.com/manual/reference/program/mongodump/


2. 복원하기

mongorestore ^

  --host={호스트:포트} ^

  --db={DB이름} ^

  --collection={Collection이름} ^

  --drop ^

  --gzip ^

  {복원될 데이터가 있는 경로명}

  --archive={복원될 데이터가 있는 파일명}


옵션> 복원할 경로명--archive 옵션은 중복 사용할 수 없음


참고> https://docs.mongodb.com/manual/reference/program/mongorestore/


Posted by jungtae17
,

새로운 DB로 백업 DB를 전체 복구하는 방법


1. 새로운 DB 설치를 위하여 MongoDB 서버를 실행한다. (DB 생성, 인증 생략)

mongod.exe ^
  --port 27017 ^
  --dbpath "{새로운 DB 경로}" ^
  --directoryperdb ^
  --noauth ^
  --rest

2. 백업된 DB를 복구한다. (전체 복구)

mongorestore.exe ^
  /port 27017 ^
  /drop ^
  "{백업 DB 경로}"

3. 재시작을 위하여 MongoDB 서버를 종료한다.


4. 운영을 위한 MongoDB 서버를 실행한다. (인증 포함)

mongod.exe ^

  --port 27017 ^

  --dbpath "{새로운 DB 경로}" ^

  --directoryperdb ^

  --auth ^

  --rest



Posted by jungtae17
,