![]() Keep in mind that in these examples, the ~/Downloads/mongodb.dump file will be created on the host machine, or at least on whatever machine you are running these commands from, not within the container. Or again, if you are using a connection URL: ❯ docker exec -i /usr/bin/mongodump -uri "" -archive > ~/Downloads/mongodb.dump This is what what would look like: ❯ docker exec -i /usr/bin/mongodump -username -password -authenticationDatabase admin -db -archive > ~/Downloads/mongodb.dump There is a flag we can use that changes the behavior of mongodump to instead send everything out into a single archive file or stdout, which we can use to directly pipe everything we need out of the container into a file on our host machine – or indeed to machine we are running these container commands from. Here I am using the ~/Downloads destination as an example: ❯ docker cp :/dump ~/Downloads/dump Method two: Pipe results directly out of the container into a single dump Now that we have the resulting files we can copy them out of the container and to our host. Or if you use a mongodb+srv or similar URL to connect to your database instead: ❯ docker exec -i /usr/bin/mongodump -uri "" -out /dump Here's an example that dumps your entire database to the /dump directory within your container: ❯ docker exec -i /usr/bin/mongodump -username -password -authenticationDatabase admin -db -out /dump For this we can use an intermediary step of storing the dumped database files in a directory within the container, which we can then copy out to our host using docker cp – or if you already have a host directory mounted as a volume, you can use that and skip the docker cp step altogether of course. If this is the method you'd like to use, we won't be able to rely on shell piping to get the files directly out of our database container. Method one: Mongodump's default individual collection dump filesīy default a mongodump export generates individual files, one for reach collection. This assumes your source database is (also) in a container, but the command would be roughly identical if you your source database is directly installed on your (virtual) machine too. ![]() We can use the following command to create a dump of your entire database, all collections included.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |