A step-by-step guide on how to backup your Mongo database on a mupx deployed Meteor app on Digital Ocean

2017–11–23 Note: MongoChef is now called Studio 3T. https://studio3t.com/

I had to do this recently, so I’m putting down what I learned in one place in case anyone needs it too.

Here’s the high level overview of what this article is about.

  1. Connecting to Mongo
  2. Backing up your database
  3. Restoring your database

Connecting to Mongo

This guide will be using MongoChef; a GUI for managing your Mongo databases. You can download it here: http://3t.io/mongochef/. It’s free for personal use.

mupx actually sets up your Meteor app in a Docker container so you actually can’t access the Mongo database directly. mupx docs say:

If you decided to use MongoDB, it’ll be also running as a Docker container. It’s bound to the local interface and port 27017 (you cannot access from the outside)

So in order to connect to Mongo we are going to have to do the following: First, let’s tell MongoChef where our database is; it exists at localhost:27017.

MongoChef — Server tab

Next, we have to SSH tunnel into our Digital Ocean droplet so that the localhost refers to the server’s Mongo database properly. Your settings may differ here, but if you are using an SSH key, it’s usually located at ~/.ssh/id_rsa (on a Mac).

If you want to learn how to set up SSH keys refer to this tutorial: https://www.digitalocean.com/community/tutorials/how-to-use-ssh-keys-with-digitalocean-droplets

MongoChef — SSH Tunnel tab

You can press Test Connection just to be sure it was set up properly. If it’s all good, save your connection, then connect to it.

Once you are connected, you should see something like this:

MongoChef — Left sidebar after you’ve connected

In case you were wondering, the appName comes from the mup.json field appName.

Backing Up Your Database

Let’s export all the collections in the appName database.

  1. Right click on the database called appName
  2. Export Collections
  3. Export Target > Specify a target folder > Format > JSON — mongo shell / 3T MongoChef
  4. Export

Once the export is done you can go to the target folder you specified and you should see a bunch of .json files in there. That’s your whole database!

Restoring Your Database

You might want to do this on a different server just in case.

  1. Right click on the database you want to import into.
  2. Import Collections
  3. Import Source Files > Click the green + > Select all the .json files you exported earlier
  4. Import Target > Select Import Mode
  5. Import

You’re done! I hoped that helped.