Start a new MongoDB container with the same version as the original container.
Mount the external volume to the new container using the -v flag in the docker run command. For example:
docker run -d --name new-mongo -v my_volume:/data/db mongo
Note that my_volume
is the name of the volume holding the MongoDB data.
docker exec -it new-mongo /bin/bash
mongodump --dbpath /data/db --out /backup
Here, /backup
is the location where the backup will be stored inside the container.
Once the backup is complete, exit the shell.
Copy the backup from the container to a local directory using the docker cp command:
docker cp new-mongo:/backup /path/to/local/backup
docker stop new-mongo
docker rm new-mongo
Start a new MongoDB container using the same command as in step 2, but this time add the --auth flag to require authentication.
Use the mongorestore command to restore the data from the backup:
mongorestore --dbpath /data/db --drop /path/to/local/backup
Here, /path/to/local/backup
is the location of the backup file on the host machine.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-05-28 06:18:42 +0000
Seen: 11 times
Last updated: May 28 '23
How to transfer MongoDB Database to a local machine?
How can the Mongo aggregation query be used in a foreach loop?
How do you log Python data into a database?
Is it possible to query a unique index directly instead of querying a collection in MongoDB?
What is the process of integrating API data into MongoDB using Spark/Python?
Please help me with connecting my MongoDB to my JS file as I am struggling to do so.
How can additional fields that have been transformed be queried in MongoDB?