I was trying to backup my mongo database on the product sever.and then restore then back to the staging server. and here comes some problem, there are a lot of collections in db, I want to igonre some collections that I don't want to restore on staging server.
I can approach this by dumpping the staging db, dumpping the producting db, and then restore the prodct to staging useing --drop option. and restore the specified collections in staging db. uh..it's really bad.
1. dump producting db
mongodump --host product-server-host --username abcd --password bcda -d db -o pruduct-dump-dir
2. dump staging db
mongodump --host staging-server-host --username abcd --password bcda -d db -o staging -dump-dir
3. restore all collection, then restore the collection back restore pruduct-dump-dir to staging server
mongorestore --host staging-server-host --username abcd --password bcda --drop pruduct-dump-dir mongorestore --host staging-server-host --username abcd --password bcda --drop --collection coll pruducting-dump-dir
Is there any option like ignore-collection when I'm dumpping? any suggestion will be appreciated :3
mongoexport is a command-line tool that produces a JSON or CSV export of data stored in a MongoDB instance. mongodump is a utility for creating a binary export of the contents of a database.
Mongdump does not lock the db. It means other read and write operations will continue normally.
The mongodump is a utility for creating database backups. The utility can be used for creating binary export of the database contents. Mongodump can export data from both mongod and mongos instances, allowing you to create backups from: A standalone, replica set.
Yes, mongodump does export the indexes created on the collection, and the indexes are restored with mongorestore along with the data.
Now available from version 3.0.0
--excludeCollection <collection_name> --excludeCollectionsWithPrefix <collection_prefix>
Repeat to exclude more than 1
Checkout the documentation
mongodump --db test --excludeCollection=users --excludeCollection=salaries
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With