MongoDB Backup and restore

Source: Internet
Author: User
Tags mongodump mongorestore

MongoDB Standalone:

To back up all libraries:

Mongodump--host 10.10.7.33:27019--gzip--OUT/HOME/MONGODB/0415_BF

To back up the specified library:

Mongodump--host 10.10.10.251:21100-d dbname--gzip-out/home/mongodb/bjdata2

Restore recovery:
Mongorestore--host <ip>:<port>--gzip/home/mongodb/bjdata

Replica backup of the set cluster:

Backup Data set:

  mongodump -h "ttlsa/10.1.1.155,10.1.1.156,10.1.1.157"--oplog -o /backup/mongodbbackup/

1. Remove the cluster from the members to be recovered in the replication set

2. Run the Mongorestore--oplogreplay command

1 # mongorestore --oplogReplay dump/

3. Create Oplog

12 > uselocal> db.createCollection("oplog.rs", {"capped" : true, "size": 10000000})

4. Restore Oplog

1 # mongorestore -d local -c oplog.rs dump/oplog.bson

Note: Oplog.bson is not located in Dump/local/oplog.rs.bson, Oplog.bson records the actions that occurred during the mongodump process.

Sharding Cluster backup and recovery

For smaller shard clusters, you can directly connect to the MONGOs for backup via Mongodump, and the backed up files will contain the metadata information and actual data of the config server.

For large shard clusters, the backup steps are as follows:

1. Close Balancer

Note: Connect to the MONGOs instead of the config server instance.

1234 > sh.setBalancerState(false) 或> sh.stopBalancer() 或> useconfig> db.settings.update( { _id: "balancer" }, { $set : { stopped: true } } , true);

2. Backing up cluster metadata

Use Mongodump to back up any one of the config servers.

You can connect directly to either one of the config Mongod instances or through the MONGOs connection.

1 # mongodump --db config

3. Back up each replica set in the Shard cluster

can be executed in parallel.

4. Enable Balancer

Note: Connect to the MONGOs instead of the config server instance.

1234 > sh.setbalancerstate ( true > sh.startbalancer () or > use config > db.settings.update ({_id: }, {$ set Code class= "Actionscript3 plain": {stopped: false }}, true

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.