mongodump/mongorestore로 아카이브 백업 및 단일 컬렉션 복원
MongoDB백업명령어
# Single database, one compressed archive file (password is prompted):
mongodump --uri="mongodb://admin@mongo1:27017/?authSource=admin" --db=shop --gzip --archive=/backup/shop_$(date +%F).archive.gz
# Dry run before restoring the archive under a different name:
mongorestore --uri="mongodb://admin@mongo1:27017/?authSource=admin" --gzip --archive=/backup/shop_2026-10-08.archive.gz --nsFrom="shop.*" --nsTo="shop_restore.*" --dryRun
# Restore a single collection from the archive under a new name:
mongorestore --uri="mongodb://admin@mongo1:27017/?authSource=admin" --gzip --archive=/backup/shop_2026-10-08.archive.gz --nsInclude="shop.musteri" --nsFrom="shop.*" --nsTo="shop_restore.*" --numInsertionWorkersPerCollection=4
# Restore under the same name, dropping the existing collection:
mongorestore --uri="mongodb://admin@mongo1:27017/?authSource=admin" --gzip --archive=/backup/shop_2026-10-08.archive.gz --nsInclude="shop.musteri" --drop하는 일
데이터베이스를 단일 gzip 아카이브 파일로 백업하고, 아카이브에서 데이터베이스 전체 또는 단일 컬렉션을 선택적으로 다른 이름(nsFrom/nsTo)으로 복원한다.
사용 시점
논리 백업, 환경 간 데이터 이동, 또는 실수로 삭제되거나 손상된 단일 컬렉션 복구에.
주의
mongodump는 논리 백업이다: 큰 데이터 세트에서는 느리고 복원 중 인덱스가 재구축된다. --oplog 없이 수행한 덤프는 운영 중인 시스템에서 시점 일관성이 없다. --drop은 복원 시작 전에 대상 컬렉션을 삭제하므로 먼저 nsTo로 다른 이름으로 복원해 확인한다. 복원은 primary에 쓰므로 복제 지연을 일으킬 수 있다.