Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mongodump ignore some specified collections

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

like image 257
sashimi Avatar asked Apr 12 '13 03:04

sashimi


People also ask

What is the difference between Mongoexport and Mongodump?

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.

Does Mongodump lock the database?

Mongdump does not lock the db. It means other read and write operations will continue normally.

What does Mongodump command do?

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.

Does Mongodump include index?

Yes, mongodump does export the indexes created on the collection, and the indexes are restored with mongorestore along with the data.


2 Answers

Now available from version 3.0.0

--excludeCollection <collection_name> --excludeCollectionsWithPrefix <collection_prefix> 

Repeat to exclude more than 1

Checkout the documentation

like image 56
Daniel Pérez Rada Avatar answered Sep 24 '22 08:09

Daniel Pérez Rada


mongodump --db test --excludeCollection=users --excludeCollection=salaries 
like image 36
Nataniel Paiva Avatar answered Sep 24 '22 08:09

Nataniel Paiva