From 5b53a227824367d53f3dc0ec740e6f2fb0a1de94 Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Sat, 20 Jun 2020 14:53:46 -0500 Subject: [PATCH] Add Dump A Remote Database as a mongo til --- README.md | 3 ++- mongodb/dump-a-remote-database.md | 37 +++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 mongodb/dump-a-remote-database.md diff --git a/README.md b/README.md index 7bf5d8b..fce5833 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ and pairing with smart people at Hashrocket. For a steady stream of TILs, [sign up for my newsletter](https://tinyletter.com/jbranchaud). -_925 TILs and counting..._ +_926 TILs and counting..._ --- @@ -392,6 +392,7 @@ _925 TILs and counting..._ ### MongoDB - [Determine The Database Version](mongodb/determine-the-database-version.md) +- [Dump A Remote Database](mongodb/dump-a-remote-database.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) diff --git a/mongodb/dump-a-remote-database.md b/mongodb/dump-a-remote-database.md new file mode 100644 index 0000000..1a29663 --- /dev/null +++ b/mongodb/dump-a-remote-database.md @@ -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. ``) with valid values for your remote mongo +instance. + +```bash +mongodump --host ':' \ + --ssl \ + --username '' \ + --password '' \ + --authenticationDatabase 'admin' \ + --out ./mongo-backups/-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.