mirror of
https://github.com/jbranchaud/til
synced 2026-01-03 07:08:01 +00:00
Add Dump A Remote Database as a mongo til
This commit is contained in:
37
mongodb/dump-a-remote-database.md
Normal file
37
mongodb/dump-a-remote-database.md
Normal file
@@ -0,0 +1,37 @@
|
||||
# Dump A Remote Database
|
||||
|
||||
Here is a single-line script for dumping a remote mongo database. This will
|
||||
dump it to your local filesystem in a binary format (`.bson`) that you can then
|
||||
restore to another mongo instance.
|
||||
|
||||
Create a file like this called `mongdump-cmd` and replace the various
|
||||
placeholder values (e.g. `<HOST>`) with valid values for your remote mongo
|
||||
instance.
|
||||
|
||||
```bash
|
||||
mongodump --host '<HOST>:<PORT>' \
|
||||
--ssl \
|
||||
--username '<USER>' \
|
||||
--password '<PASSWORD>' \
|
||||
--authenticationDatabase 'admin' \
|
||||
--out ./mongo-backups/<DATE>-dump
|
||||
```
|
||||
|
||||
Create the backup directory:
|
||||
|
||||
```bash
|
||||
$ mkdir mongo-backups
|
||||
```
|
||||
|
||||
Then execute the bash script:
|
||||
|
||||
```bash
|
||||
$ bash mongodump-cmd
|
||||
```
|
||||
|
||||
This will dump everything on the remote instance into the
|
||||
`mongo-backups/2020-06-20-dump/` directory. You can also include the `--db`
|
||||
flag to dump a specific database.
|
||||
|
||||
This can later be used with `mongoresetore` to restore the data to the mongo
|
||||
instance you specify.
|
||||
Reference in New Issue
Block a user