Hello,
We are using a fairly basic backup strategy. Every day, we dump our entiry collections (although we have just one for now) with:
mongodump --uri="mongodb://backup@mongo1:27017,mongo2:27017,mongoarb:27017/?replicaSet=rs0&readPreference=secondaryPreferred" --oplog --gzip --out="C:\Temp\MongoBackups\"
Assuming I’m only interested in my LCB.jobs database…
My questions:
-
If I want to restore just the documents the were deleted, is it just a matter of ignoring the duplicate key errors from:
mongorestore --uri="mongodb://admin@mongo1:27017,mongo2:27017,mongoarb:27017/?replicaSet=rs0" --dir="C:\Temp\MongoBackups\" --nsInclude="LCB.jobs" --gzip
continuing through error: E11000 duplicate key error collection: LCB.jobs index: _id_ dup key: { _id: "xxxxxxxxxxx" }
Is there a way to tell it to try and restore only the missing ones, as to not have these errors showing up?
-
Even better, how could I eventually restore specific document(s)? The only way I could think of right now is to restore the hole collection into another temporary collection, and then manually go in and get the documents from there and update the good collection afterwards with it, i.e.:
mongorestore --uri="mongodb://admin@mongo1:27017,mongo2:27017,mongoarb:27017/?replicaSet=rs0" --dir="C:\Temp\MongoBackups\" --nsInclude="LCB.jobs" --nsFrom="LCB.jobs" --nsFrom="LCB.jobs_restore" --gzip --drop // specifying drop to make sure it's a clean temp restore
…then update LCB.jobs.documentID with values from
LCB.jobs_restore.documentID type of thing.Once finished, cleanup with
db.jobs_restore.drop()
Is there a better way for this?
Much thanks for your precious time.
Pat.