MongoDB Backup and restore

Source: Internet
Author: User
Tags mongodump

Backup of the data is very much in the two ways, of course, you can also take advantage of the snapshot:


---------------------------------------------------------------------

One, direct copy data file Mode backup restore

----------------------------------------------------------------------


Note: When calling the Db.fsyncunlock () and Db.fsynclock () commands, do not close the shell, because if you enable authentication or disconnect the link, you may not be able to connect, and you will need to restart the Mongod, these commands will be invalidated.


1. Lock the database: Db.fsynclock ()

This command disables all writes and writes dirty pages to disk to ensure that the data no longer changes. This time the write operation will be queued in memory until the database is unlocked.


2.mkdir/mongodbback/zou

Cp-r/server/mongo/data/*/mongodbback/zou

3. Unlocking the Database Db.fsyncunlock ()

After the backup is complete, then how to reply?

4. Cp-r/mongodb/zou/*/server/mongo/data/


Attention:

You should ensure that Mongod is not running and/server/mongo/data/is empty before you restore.

Be sure to confirm that the CP command executed successfully before deleting it.

After the restore is complete, start mongod again.

Start Mongod Use the command: mongod-f/etc/mongod.conf--fork--nojournal



-----------------------------------------------------------------------------

Second, mongodump backup

-----------------------------------------------------------------------------


1. Database Mongod Backup in a state that is not running

Mongodump--dbpath/server/mongo/data/--out/backup/zou/mongo

Restore when the database is not started

Mongorestore--dbpath/backup/zou/mongo/--journal/server/mongo/data

If you want to specify a backup restore a specific database by specifying the name of the database folder under File path

2. Remote link for backup

Mongodump--host www.zou.com--port 27017--username Zou--password 123.com--out/backup/zou/mongo/mongodump-2016-03-11

Recovery

Mongodump--host www.zou.com--port 27017--username Zou--password 123.com/backup/zou/mongo/mongodump-2016-03-11

3. Using Oplog for backup

Mongodump is not a snapshot backup, and the system may continue to operate during the backup process.

The Oplog setting is to prevent this from happening, but the premise of using Oplog is that the--replset option is used Mongod startup

Backup and restore same as 2, except with--oplog and Oplogreplay parameters


This article is from the "Arctic Linux" blog, be sure to keep this source http://941012521.blog.51cto.com/9253690/1749991

MongoDB Backup and restore

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.