Backups for MongoDB
For a general overview of how and when backups are taken on the Compose platform, have a look at the Backups page.
How MongoDB Backups Are Made
MongoDB deployments are backed-up daily, weekly, and monthly and retained according to the standard schedule.
We backup your deployment with a file-system snapshot of the backup data node. (You can see which is the backup data node from the Resources pane in the Compose UI.) This minimizes the impact that taking a backup snapshot has on your application or service by keeping it in the background away from your primary and secondary nodes. The snapshot is a complete picture of your data, and doesn't rely on any past backups or files, so any one backup can be used to do a full restore.
Downloading Your Backups
All automatic backups, and your latest on-demand backup, are available from the Compose UI in the Backups panel. To download a backup file, click on the download icon on the right. (It's the one with the arrow pointing into the box.)
Your browser should pop up a dialog or start downloading a compressed file with the backup_id as the file name. The files inside the uncompressed folder are the snapshot.
You may also download backups from the Compose API by sending a GET request with the MongoDB deployment_id and the backup_id to the
/2016-07/deployments/:deployment_id/backups/:backup_id endpoint. More complete instructions live in the Managing Backups via the Compose API page.
The easiest way to make an on-demand back up of your MongoDB is to use the Back up Now button on the Backups panel in the Compose UI. When the backup is complete, it will be available under On-demand backups.
Backups can be made on-demand via the API endpoint
/2016-07/deployments/:id/backups. For more about how to trigger and download these backups, see the Managing Backups via the Compose API page.
If you have the MongoDB tools installed (or a local install of MongoDB), you may use a utility named "
mongodump", which can export data from a running MongoDB instance to a local file system. You may run
mongodump against your backup database from the command-line like this (files will be stored in the
dump/ directory relative to your current working path):
mongodump --ssl --sslAllowInvalidCertificates --host <hostname> --port <portnumber> --db <database_name> -u <username> -p <password>
In this case the username and password is a user created in that specific database. If you use the admin database for user administration and permissions, add the
--authenticationDatabase admin parameter to the above command.
Mongo Drivers 2.x vs. 3.x
If you are using an older (2.x) MongoDB tools version, you may need to remove the space between the -p and the database password.
How to Restore a MongoDB Backup
MongoDB on Compose backups are restorable to a new deployment from the Backups panel in the Compose UI. To restore a backup in this fashion, click on the restore icon. (It's the one with the arrow in a circle.)
You should then see a page where you can name the new deployment, and choose its region. You may also elect to use the WiredTiger storage engine, if you are restoring data from a deployment currently using it or if you wish to change from MMAPv1 to WiredTiger.
Clicking on the Create Deployment button starts the provisioning and the restoration of your data.
Backups can be restored by sending a POST request to the
/2016-07/deployments/:deployment_id/backups/:backup_id/restore endpoint. For more information on this process, please refer to the Managing Backups via the Compose API page.
mongorestore utility uses the dump files created by
monogdump to send a series of inserts to the target database, but ignoring duplicate records. If your data is largely "write once", this is a good way to merge backup data with production.
This process will not apply updates that may have happened since the backup was made, and will reinsert any since deleted documents.
If you have the MongodDB Tools installed (or a local install of MongoDB), you may run
mongorestore against your target database. The
dump/ should be in the directory relative to your current working path, and the database_name will be the database you exported from.
mongorestore --ssl --sslAllowInvalidCertificates --host <hostname> --port <portnumber> --db <database_name> -u <username> -p<password> dump/database_name
In this case the username and password is a user created in that specific database. If you use the admin database for user administration and permissions the command will look like this:
mongorestore --ssl --sslAllowInvalidCertificates --host <hostname> --port <portnumber> --db <database_name> -u <username> -p<password> --authenticationDatabase admin dump/database_name
The lack of a space between the -p and your database password is significant.
Running Backups Locally
To get a local restore of your databases and data, you will need to have MongoDB tools and a local install of MongoDB. After you have these, there are a couple of restore options. To use the data taken from mongodump, using mongorestore, you can use the local host, port number, and user access settings to get your data locally.
If you are using one of the backup archives that is a snapshot you can extract the data into a new directory, and bring up a local MongoDB instance with the command
mongod --dbpath ./db where './db' is where the extracted data now lives.
Bringing Local Backups in to Compose
If you have been running MongoDB locally and would like to migrate the data into Compose, you may do so using
mongodump on the local instance should look something like:
mongodump --db <database_name> -u <username> -p<password>
Then you can use the
mongorestore commands from above(here) to restore to an already existing MongodDB Compose deployment.
Still Need Help?
If this article didn't solve things, summon a human and get some help!
Updated over 3 years ago