Learn how to created automated backups of your MongoDB databases to be stored on Filebase.
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.
Edit the values to reflect your local configuration.
# Your User’s home directory
# Your server's hostname
# Your database name to be backed up
# S3 bucket name
# Linux user account
# Current time
# Backup directory
# Tar file of backup directory
# Create backup dir (-p to avoid warning if it already exists)
/bin/mkdir -p $DEST
echo "Backing up $HOST/$DBNAME to s3://$BUCKET/ on $TIME";
# Dump from mongodb host into backup directory
/usr/bin/mongodump -h $HOST -d $DBNAME -o $DEST
# Create tar of backup directory
/bin/tar cvf $TAR -C $DEST .
# Upload tar to s3
/usr/bin/aws --endpoint https://s3.filebase.com s3 cp $TAR s3://$BUCKET/ --storage-class STANDARD_IA
# Remove tar file locally
/bin/rm -f $TAR
# Remove backup directory
/bin/rm -rf $DEST
# Confirm success
echo "Backup of MongoDB databases to Filebase bucket $BUCKET completed successfully. "
This script uses the
mongodbdumpfunction 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.
It should return the following output:
In your Filebase bucket, you should see the tar file uploaded:
Open your crontab with the following command:
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!