When you use externally hosted MongoDB, you must manage the backups yourself. The following guide explains how to configure the backups.
Create a Backup
Mongodump is the utility for creating backups for externally hosted database.
mongodump --host=mongodb1.example.net --port=37017 --username=user --authenticationDatabase=admin --out=/opt/backup/mongodump-2023-05-05
–db=kendis
Note: You must schedule a script or similar setup to take the backups on a daily/regular basis.
Archive Option
An archive is a backup in a single file rather than a folder.
For making an archive as an output, use the following command.
mongodump --host=mongodb1.example.net --port=37017 --username=user --authenticationDatabase=admin --archive=/opt/backup/mongodump-2023-05-05.archive –db=kendis
Restore from backup
mongorestore --uri="mongodb://user@mongodb1.example.net:27017/?authSource=admin" /opt/backup/mongodump-xxxxxxxxxx
Restoring from the archive dump
mongorestore --uri="mongodb://user@mongodb1.example.net:27017/?authSource=admin" --archive=/opt/backup/mongodump-xxxxxxxxxx.archive
Important Note:
Above are example commands for your reference, exact commands may vary depending on your MongoDB database version.
For further reference