0

If I get it right if to make mongodump in to directory that already contains previous dumped data it will still download full collection data even if is not different from data containing in the dir Though it could check the metadata. Is there a way to make it not download collection if it has not "changed" in terms I described?

Mongodb version 4.0.4

  • What is the MongoDB version(x,y,z)? – Md Haidar Ali Khan Dec 24 '18 at 18:08
  • Mongodb version 4.0.4 – WHITECOLOR Dec 24 '18 at 18:15
  • You can edit your tag anytime. – Md Haidar Ali Khan Dec 24 '18 at 18:20
  • I have updated the answer according to your requirement. As per MongoDB documents mongodump overwrites output files if they exist in the backup data folder. – Md Haidar Ali Khan Dec 24 '18 at 18:21
  • 1
    As at MongoDB 4.0, collection metadata doesn't include a last modified timestamp and there is no record of when mongodump last ran (or what collections were dumped). If you have a means of identifying when a collection last changed you could perhaps write a custom script using mongodump with the --excludeCollection option. What sort of deployment do you have (standalone, replica set, or sharded cluster)? Data changes could be identified for a replica set using the replication oplog (assuming the oplog hasn't rolled over since you took your last backup). – Stennie Dec 27 '18 at 2:42
0

If I get it right if to make mongodump in to directory that already contains previous dumped data it will still download full collection data even if is not different from data containing in the dir Though it could check the metadata. Is there a way to make it not download collection if it has not "changed" in terms I described?

As per MongoDB documentation here mongodump overwrites output files if they exist in the backup data folder. Before running the mongodump command multiple times, either ensure that you no longer need the files in the output folder (the default is the dump/ folder) or rename the folders or files.

When you run mongodump without any arguments, the command connects to the MongoDB instance on the local system (e.g. localhost) on port 27017 and creates a database backup named dump/ in the current directory.

To backup data from a mongod or mongos instance running on the same machine and on the default port of 27017, use the following command:

mongodump

You can also specify the --host and --port of the MongoDB instance that the mongodump should connect to. For example:

mongodump --host mongodb.example.net --port 27017

To specify a different output directory, you can use the --out or -o option:

mongodump --out /data/backup/

For further your ref here

  • Ok, actually the answer is that it not possible that I wanted in OP. – WHITECOLOR Dec 27 '18 at 22:21
0

As at MongoDB 4.0, collection metadata doesn't include a last modified timestamp and there is no record of when mongodump last ran (or what collections were dumped).

You could write a custom script if you have a means of identifying relevant changes in your deployment since your last backup timestamp, but there are some potentially tricky aspects such as documents that have been removed.

One approach would be to use Change Streams to keep track of relevant collections that have changed since the last backup time, but this would require a replica set deployment. It is definitely possible to configure a single member replica set deployment if that suits your requirements.

It would be more ideal to use a supported backup method if your actual goal is incremental backups rather than per-collection mongodump.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.