MongoDB
Learn how to created automated backups of your MongoDB databases to be stored on Filebase.
What is MongoDB?
MongoDB is a cross platform database program that uses JSON-like documents. MongoDB is open source and free to download and self-host on any server.
Read below to learn how to set up automated backups of your MongoDB databases to be stored in a Filebase bucket.
This guide was written using Ubuntu 20.04. Commands and workflow may vary depending on your operating system.
1. Copy the following script onto your server and save it as mongodb_backup.sh
.
mongodb_backup.sh
.Edit the values to reflect your local configuration.
This script uses the mongodbdump
function to create a backup dump of all MongoDB databases and stores it to a tar file that is then uploaded to Filebase using an AWS CLI command.
2. Run the script to test that your configuration works as expected.
It should return the following output:
In your Filebase bucket, you should see the tar file uploaded:
3. Set up automation of this script using a cronjob.
Open your crontab with the following command:
crontab -e
4. Add the following line to your crontab to create a cronjob that runs your mongodb_backup.sh script:
0 8 * * * /path/to/mongodb_backup.sh
Replace the file path with the correct path for your configuration.
This cronjob is scheduled to run every day at 8:00AM on your server. Configure the cronjob values to reflect your desired configuration.
You’ve now configured automated backups for your MongoDB databases!
Last updated