MongoDB Backup, Restore, and Replica Set Workflows

Use mongodump, mongorestore, replica set commands, and diagnostic tools for operational MongoDB workflows.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all
## Backup and restore
Dump one database
mongodump --uri="mongodb://localhost:27017/appdb" --out=./dump

# Create a binary dump of a database.

Dump one collection
mongodump --uri="mongodb://localhost:27017/appdb" --collection=users --out=./dump

# Back up only a single collection.

Restore a dump and drop existing data first
mongorestore --uri="mongodb://localhost:27017/appdb" --drop ./dump

# Restore into a collection or database after clearing prior content.

Restore only selected namespaces
mongorestore --uri="mongodb://localhost:27017" --nsInclude="appdb.users" ./dump

# Restore a subset of data from a larger dump.

Create a compressed archive dump
mongodump --uri="mongodb://localhost:27017/appdb" --archive | gzip > appdb.archive.gz

# Stream a dump to a gzip archive.

## Replica set and diagnostics
Check replica set status
rs.status()

# Inspect members, state, and health.

Initiate a simple replica set
rs.initiate()

# Initialize a replica set on a self-managed deployment.

Watch server metrics with mongostat
mongostat --uri="mongodb://localhost:27017"

# See high-level runtime activity.

Watch read and write time with mongotop
mongotop --uri="mongodb://localhost:27017"

# See how much time collections spend reading and writing.

Recommended next

No recommendations yet.