•  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
분류
1. 개요2. 설치 Guide
2.1. 설치 후 최초 설정
3. 백업 및 복구
3.1. 백업3.2. 복원3.3. 복원 후 확인 방법

1. 개요 [편집]

  • MongoDB [1]
  • 몽고DB
  • NoSQL DB의 일종
  • 도큐먼트 지향 DB
  • 고성능, 스키마 없음. 오픈소스
  • 쿼리, 인덱스 용이
  • BSON[2]으로 계층형 데이터 표현
  • AP특성에 맞는 구조로 데이터를 격납
  • JSON 형식의 데이터를 REST 엔드포인트로 송수신
  • 자바스크립트, JSON 문법으로 데이터 질의, 조작 가능
  • 서비스 기본포트: 27017

2. 설치 Guide [편집]

2.1. 설치 후 최초 설정 [편집]

  • 아래 내용은 mongoDB 8버전대 기준으로 설명함.
  • mongosh 명령어로 mongoDB CLI 환경 진입
  • db.createUser를 통해 admin ID 생성
    • 예시
db.createUser(
{
user: "kskim",
pwd: passwordPrompt(),
roles: [
{ role: "userAdminAnyDatabase", db: "admin" },
{ role: "readWriteAnyDatabase", db: "admin" }
]
}
)
  • 이후 admin ID를 통해 다른 사용자 ID나 추가 작업 수행
  • 예시
#mongosh
Current Mongosh Log ID: 67f745b38d50f7b8b9d861df
Connecting to: mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&>appName=mongosh+2.5.0
Using MongoDB: 8.0.6
Using Mongosh: 2.5.0

For mongosh info see: https://www.mongodb.com/docs/mongodb-shell/


To help improve our products, anonymous usage data is collected and sent to MongoDB periodically (https://www.mongodb.com/legal/privacy-policy).
You can opt-out by running the disableTelemetry() command.

The server generated these startup warnings when booting
2025-04-10T02:35:54.496+00:00: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine. See http://dochub.mongodb.org/core/prodnotes-filesystem
2025-04-10T02:35:56.152+00:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
2025-04-10T02:35:56.155+00:00: You are running on a NUMA machine. We suggest launching mongod like this to avoid performance problems: numactl --interleave=all mongod [other options]
2025-04-10T02:35:56.156+00:00: For customers running the current memory allocator, we suggest changing the contents of the following sysfsFile
2025-04-10T02:35:56.156+00:00: For customers running the current memory allocator, we suggest changing the contents of the following sysfsFile
2025-04-10T02:35:56.156+00:00: We suggest setting the contents of sysfsFile to 0.
2025-04-10T02:35:56.156+00:00: We suggest setting swappiness to 0 or 1, as swapping can cause performance problems.


test> use admin
switched to db admin
admin> db.createUser(
... {
... user: "kskim",
... pwd: passwordPrompt(),
... roles: [
... { role: "userAdminAnyDatabase", db: "admin" },
... { role: "readWriteAnyDatabase", db: "admin" }
... ]
... }
... )
Enter password
**********{ ok: 1 }
admin> exit

3. 백업 및 복구 [편집]

  • 아래 내용은 mongoDB 8버전대 기준으로 설명함.
  • 역시 공식 사이트에 백업 방법들과 예시가 소개가 되어있다.
  • 여기에서는 실제 일부 명령어만 기록한다.

3.1. 백업 [편집]

mongodump -u <유저명> -p <비밀번호> --authenticationDatabase admin [3] --db <원하는 DB> --out <백업 디렉토리>

-예시
mongodump -u userKskim -p 'password123'[4] --authenticationDatabase admin --db myDbName --out /home/backup/mongo/

3.2. 복원 [편집]

mongorestore -u <유저명> -p <비밀번호>[5] --authenticationDatabase admin[6] --db myDbName /home/backup/mongo/myDbName/
  • 이후 해당 DB CLI 또는 UI Client로 접속해서 해당 DB값을 확인한다.

3.3. 복원 후 확인 방법 [편집]

  • mongoDB shell(mongosh) CLI 진입 후
  • DB전체의 용량 확인.
  • 전체 용량이 비슷하다면 잘 복원되었을 가능성이 높다.
db.stats().dataSize
  • Collection 개수 확인.
  • 양쪽의 Collection의 개수를 확인한다.
show collections
  • 각 collection 별로 내부 데이터 개수 확인.
db.(coleection 이름).estimatedDocumentCount()
[1] 거대한 DB(humongous DB)에서 따옴[2] 바이너리 JSON[3] <인증DB> 이름이 다를 경우 다른걸 쓴다. 보통은 admin[4] 반드시 ''로 감싸야한다[5] 마찬가지로 반드시 ''로 감싸야한다[6] authenticationDatabase를 명시하지 않으면 기본적으로 myDbName에서 인증정보를 찾는다. 꼭 명시하도록 하자