Back up and restore Document Databases with MongoDB® tools
Managed Document Databases provide fully-managed document Database Instances, with a MongoDB®-compatible API layer over a PostgreSQL engine to store and retrieve data.
This means you can use MongoDB® command line tools to use and manage your Document Databases.
This tutorial shows how to backup and restore your Document Databases with the MongoDB®
mongorestore command line database tools.
You may need certain IAM permissions to carry out some actions described on this page. This means:
This tutorial shows you basic restore and backup operations. If you need additional options for the operations, refer to the official MongoDB® documentation.
Make sure you keep the
--sslCAFile=<file.pem> options in your commands, as you will need to authenticate using the default SSL certificate when you connect to your Database Instance.
To create backups, we will use the
mongodump tool, which can create backups for an entire Database Instance, logical database or collection. It can also use a query to back up part of a collection.
Navigate to the Scaleway console.
Click Document Databases under Managed Databases on the side menu. A list of your Database Instances displays.
Click the database name or «See more Icon» > More info to access the Database Instance information page.
Download the Database Instance’s SSL certificate.Important:
Make sure you know the path to the certificate in your local machine, as it will be used in a later step.
Run the following command, replacing the values according to the table below.mongodump \--host=<ip-address> \--port=<port> \--username=<username> \--password="<password>" \--out=/path/to/backup \--ssl \--sslCAFile=<file.pem> \--authenticationMechanism=PLAIN
- the IP address of your Database Instance
- the connection port of your Database Instance
- the username of the database user created upon Database Instance creation
- the password of the database user created upon Database Instance creation
- the path to the folder where you want the backups to be stored on your machine
- the path to where your SSL certificate is stored
- the list of authentication mechanisms the server accepts
If no response is returned, the operation was successful. You can make sure the backup occurred by checking if new files were added to the destination folder.
You can restore either an entire database backup or a subset of a backup using
The tool restores binary backups created using
You can restore the backed up data to any database within any Database Instance.
Run the following command, replacing the values according to the table above. You must specify the name of the destination
mongorestore \--host=<ip-address> \--port=<port> \--username=<username> \--password=<password> \/path/to/backup \--db=rdb \--ssl \--sslCAFile=<file.pem> \--authenticationMechanism=PLAIN
- the name of the database to which you want to restore the backup
If the procedure was successful, you will see an output like the following:
2023-09-04T17:50:29.893+0200 1 document(s) restored successfully. 0 document(s) failed to restore.