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.
- Connecting to Mongo
- Backing up your database
- 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.
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
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:
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.
- Right click on the database called appName
- Export Collections
- Export Target > Specify a target folder > Format > JSON — mongo shell / 3T MongoChef
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.
- Right click on the database you want to import into.
- Import Collections
- Import Source Files > Click the green + > Select all the .json files you exported earlier
- Import Target > Select Import Mode
You’re done! I hoped that helped.