Skip to content

4.0 Backup and Restore

Olga Arsenieva edited this page Nov 29, 2018 · 5 revisions

4.0 Backup and Restore Methods

Backup Methods: mongodump and mongorestore

  • The mongodump command can be used to create a BSON data dump of MongoDB contents. The mongorestore command is used to restore BSON data dump to MongoDB.
  • these commands should be run outside of shell and from mongo installation's \bin folder.
  • These commands can be used to back up contents of entire instance, a database, a collection or query results.
  • Mongodump only gets documents not indices, indexes are recreated later by mongorestore.
  • Needs mongod to be running. Not advisable to use db.fsyncLock()/ db.fsyncUnlock()
  • Good for small deployment backups or when other tools are not available. Can slow down performance if memory does not fit all data (for large data), because it reads entire database through memory. For large data it is recommended to use replica sets and run mongodump on a secondary server to preserve performance.
  • Can be used with gzip files and has archive option

mongodump --host <server:port> --db <dbname> --collection <collectionname> --out <filepath>

mongorestore --host <server:port> --db <dbname> --collection <collectionname> --drop <filepath>

Options:

--host [server:port]

connect to serverName:portNumber (localhost if omitted)

--db [dbname]

select database to backup/restore to. May need to add database name to dump path

--collection [collectionname]

select collection to dump/restore to (needs --db present). may need to add database and collection name to path

--nsInclude [databasename].[collectionname]

In the future will replace --db and --collection to specify which database/collection to restore. Can be used with wildcards

--query="{ status: 'A' }" add query to filter output

--drop mongorestore by default inserts all records. If a record with same id exists, it is not overwritten. Mongorestore with --drop will delete the records and recreate the data in BSON dump.

Replica sets

Replica sets have oplogs. This allows running mongodump with --oplog and mongorestore with --oplogReplay options that allow point in time backups.

Backup Methods: Cloud Manager

  • Cloud Manager: for cloud based MongoDB deployments that are not on the MongoDB cloud
  • A Backup Agent runs within infrastructure and automatically backs up replica sets and sharded clusters by creating snapshots of data at user-specified intervals,
  • Allows recovery from snapshot or from checkpoint between snapshots, and at selected points in time
  • Snapshots are full backups, stored by MongoDB organization and and storage costs money. Size of snapshot = size of all indexes + documents for all databases

Backup Methods: Ops Manager

  • Ops Manager: for non-cloud MongoDB deployments.
  • Same software as Cloud Manager but can be installed on own infrastructure, available in Enterprise Advanced subscriptions.

More info from MongoDB's website