|
| 1 | +# Dump And Restore With A Single gzip File |
| 2 | + |
| 3 | +The `mongodump` and `mongorestore` utilities provide a way for grabbing all the |
| 4 | +data from one database and putting it into another database. These commands are |
| 5 | +useful for transitioning production data to a database instance with more |
| 6 | +computing resources. |
| 7 | + |
| 8 | +The `--archive` and `--gzip` flags, supported by both commands, are what allow |
| 9 | +us to do the whole process with a single file. Without flags, `mongodump` will |
| 10 | +output multiple `.bson` files. |
| 11 | + |
| 12 | +Here is what the `mongodump` command might look like pointed at a remote URI: |
| 13 | + |
| 14 | +```bash |
| 15 | +mongodump \ |
| 16 | + --uri="mongodb+srv://<USER>:<PASSWORD>@<CLUSTER-HOST-URL>" \ |
| 17 | + --archive="myapp-dump.20221105.gz" \ |
| 18 | + --gzip |
| 19 | +``` |
| 20 | + |
| 21 | +This will take a little while to run based on the size of the database. The |
| 22 | +result will be a file in your current directory with the name |
| 23 | +`myapp-dump.20221105.gz`. Because it is gzip'd, it will be a few times smaller |
| 24 | +than the standing database. |
| 25 | + |
| 26 | +To then load all the data into your new Mongo database cluster, you'll use |
| 27 | +`mongorestore` with all the same flags, making sure to swap out the destination |
| 28 | +URI details with those of the new instance. |
| 29 | + |
| 30 | +```bash |
| 31 | +mongorestore \ |
| 32 | + --uri="mongodb+srv://<USER>:<PASSWORD>@<NEW-CLUSTER-HOST-URL>" \ |
| 33 | + --archive="myapp-dump.20221105.gz" \ |
| 34 | + --gzip |
| 35 | +``` |
| 36 | + |
| 37 | +For more details, see [Output an Archive |
| 38 | +File](https://www.mongodb.com/docs/database-tools/mongodump/#output-to-an-archive-file) |
| 39 | +and [Compress the |
| 40 | +Output](https://www.mongodb.com/docs/database-tools/mongodump/#compress-the-output). |
0 commit comments