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 |
> use local > 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() 或 > use config > 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