Hi @Prashant_Panchal,
If you are running on MongoDB Atlas, the easiest way to backup your data is simply to activate the Cloud Backups.
If you are not running on Atlas (or Ops Manager), you have a lot more work to do.
First, your backup strategy depends on your configuration. If you are running a 4.2+ sharded cluster that have sharded transactions in progress, mongodump
& mongorestore
cannot be part of your backup strategy as they do not maintain the atomicity of transactions across shards.
See doc: https://docs.mongodb.com/database-tools/mongodump/#sharded-clusters
Second, mongodump
can be a valid solution for all the other cases (Replica Sets, etc) but there are many details that needs to be taken into account like Read Preference or the performance impact on your production cluster.
Regarding your password error, I could be wrong be I think it’s a warning.
Here is probably the format you probably used:
mongodump --uri mongodb+srv://<USER>:<PASSWORD>@clustername.ajv83.mongodb.net/<DATABASE>
If I execute this command line in Linux, the user & password are saved in the command history which is a security issue.
And I get this warning:
2021-04-13T18:06:34.605+0200 WARNING: On some systems, a password provided directly in a connection string or using --uri may be visible to system status programs such as `ps` that may be invoked by other users. Consider omitting the password to provide it via stdin, or using the --config option to specify a configuration file with the password.
But the dump worked as expected.
2021-04-13T18:06:35.438+0200 writing bot.jobs to dump/bot/jobs.bson
2021-04-13T18:06:35.533+0200 writing bot.max_items to dump/bot/max_items.bson
2021-04-13T18:06:35.774+0200 done dumping bot.jobs (45762 documents)
2021-04-13T18:06:35.780+0200 done dumping bot.max_items (25645 documents)
To avoid sending my password in the command line history, I can do this instead:
$ mongodump --uri mongodb+srv://<USER>@clustername.ajv83.mongodb.net/<DATABASE>
Enter password:
2021-04-13T18:09:52.719+0200 writing bot.jobs to dump/bot/jobs.bson
2021-04-13T18:09:52.814+0200 writing bot.max_items to dump/bot/max_items.bson
2021-04-13T18:09:53.018+0200 done dumping bot.jobs (45762 documents)
2021-04-13T18:09:53.047+0200 done dumping bot.max_items (25645 documents)
As the password is missing, mongodump
prompts me for my user password.
Don’t forget to backup all the databases as mongodump is just saving the one you are targeting.
Cheers,
Maxime.