mirror of
https://github.com/jbranchaud/til
synced 2026-01-02 22:58:01 +00:00
Add Dump And Restore With A Single gzip File as a MongoDB TIL
This commit is contained in:
@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
|
||||
|
||||
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
|
||||
|
||||
_1263 TILs and counting..._
|
||||
_1264 TILs and counting..._
|
||||
|
||||
---
|
||||
|
||||
@@ -521,6 +521,7 @@ _1263 TILs and counting..._
|
||||
|
||||
- [Determine The Database Version](mongodb/determine-the-database-version.md)
|
||||
- [Dump A Remote Database](mongodb/dump-a-remote-database.md)
|
||||
- [Dump And Restore With A Single gzip File](mongodb/dump-and-restore-with-a-single-gzip-file.md)
|
||||
- [Get Size Stats For A Collection](mongodb/get-size-stats-for-a-collection.md)
|
||||
- [List Size Stats For All Collections](mongodb/list-size-stats-for-all-collections.md)
|
||||
|
||||
|
||||
40
mongodb/dump-and-restore-with-a-single-gzip-file.md
Normal file
40
mongodb/dump-and-restore-with-a-single-gzip-file.md
Normal file
@@ -0,0 +1,40 @@
|
||||
# Dump And Restore With A Single gzip File
|
||||
|
||||
The `mongodump` and `mongorestore` utilities provide a way for grabbing all the
|
||||
data from one database and putting it into another database. These commands are
|
||||
useful for transitioning production data to a database instance with more
|
||||
computing resources.
|
||||
|
||||
The `--archive` and `--gzip` flags, supported by both commands, are what allow
|
||||
us to do the whole process with a single file. Without flags, `mongodump` will
|
||||
output multiple `.bson` files.
|
||||
|
||||
Here is what the `mongodump` command might look like pointed at a remote URI:
|
||||
|
||||
```bash
|
||||
mongodump \
|
||||
--uri="mongodb+srv://<USER>:<PASSWORD>@<CLUSTER-HOST-URL>" \
|
||||
--archive="myapp-dump.20221105.gz" \
|
||||
--gzip
|
||||
```
|
||||
|
||||
This will take a little while to run based on the size of the database. The
|
||||
result will be a file in your current directory with the name
|
||||
`myapp-dump.20221105.gz`. Because it is gzip'd, it will be a few times smaller
|
||||
than the standing database.
|
||||
|
||||
To then load all the data into your new Mongo database cluster, you'll use
|
||||
`mongorestore` with all the same flags, making sure to swap out the destination
|
||||
URI details with those of the new instance.
|
||||
|
||||
```bash
|
||||
mongorestore \
|
||||
--uri="mongodb+srv://<USER>:<PASSWORD>@<NEW-CLUSTER-HOST-URL>" \
|
||||
--archive="myapp-dump.20221105.gz" \
|
||||
--gzip
|
||||
```
|
||||
|
||||
For more details, see [Output an Archive
|
||||
File](https://www.mongodb.com/docs/database-tools/mongodump/#output-to-an-archive-file)
|
||||
and [Compress the
|
||||
Output](https://www.mongodb.com/docs/database-tools/mongodump/#compress-the-output).
|
||||
Reference in New Issue
Block a user