First, backup
1. Lock the database:
Use admin
Db.runcommand ({fsync:1,lock:1})
{
"Info": "Now locked against writes, use Db.fsyncunlock () to unlock",
" seealso": "Http://www.mongodb.org/display/DOCS/fsync+Command",
"OK": 1
}
Fsync: Forcing all buffers to be written to disk
Lock: Locked, unable to write (all write operations will block)
2. Start Backup ...
mongodump-d mailaccess-c mail-q ' {User: "[email protected]"} '-o/data/dump
back up mailaccess database's mail collection to/data/dump directory
- D: Which database to back up
- C: Backup which collection (optional, does not pass the default is the entire database)
- Q: Specifies the condition of the backup collection (used with the-c parameter)
3. Unlock after Backup:
Use admin
Db. $cmd. Sys.unlock.findOne ()
{"OK": 1, "info": "Unlock Completed"}
second, restore:
mongorestore-d ma–drop/data/dump/mailaccess
Restore the Mailaccess database in the/data/dump directory to the MA databases
- D: Which database to restore to
–drop means to delete the original collection (if one exists) before recovery
MongoDB non-stop machine backup