Scheduled backup MongoDB database using mongodump and cron

mkdir backup
touch monitoring.sh
#!/bin/bash
 
currentDate=`date +"%Y%m%d%H%M"`
dirName="monitoring_$currentDate"
filePath=/home/mahmood/backup/$dirName
mkdir $filePath
mongodump --db monitoring --out $filePath
sudo chmod +x monitoring.sh
sudo crontab -e
30 4 * * * /home/mahmood/backup/monitoring.sh

References
https://stackoverflow.com/questions/35574603/run-cron-job-everyday-at-specific-time
https://tecadmin.net/get-current-date-and-time-in-bash/
https://askubuntu.com/questions/350861/how-to-set-a-cron-job-to-run-a-shell-script
https://coderwall.com/p/hdmmnq/easy-automatic-nightly-backups-for-mongodb

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.