Create Local Backup of MongoDB and Send Telegram Notification
- Published on
- /3 mins read/---
I was Looking for a Quick solution to get mongoDB data Backup and notification in telegam.
Got many awesome tutorial, but my needs is bit different. So i solved it and sharing with you , so that you can use if its match with you.
First, let's start by creating a new Bash script file. You can use any text editor you prefer, but for this tutorial, we'll use the nano editor. Open your terminal and run the following command
This will create a new file called backup_script.sh and open it in the nano editor. Now, copy and paste the following code into the file:
Now copy this code and paste into backup_script.sh
Before you run the script, you need to update some variables.
Replace your_database_name with the name of your MongoDB database, /path/to/backup/directory with the path to the directory where you want to store your backups, /path/to/zip/directory with the path to the directory where you want to store your compressed backups, your_username and your_password with your MongoDB username and password, your_mongodb_host with the host of your MongoDB instance (e.g. cluster0.mongodb.net), your_telegram_bot_token with the token of your Telegram bot, and your_telegram_chat_id with the chat ID of the Telegram chat where you want to receive notifications about your backups.
Save the changes by pressing Ctrl+O, then Enter, and exit nano by pressing Ctrl+X.
Now, you can run the script by executing the following command in your terminal:
chmod +x backup_script.sh
./backup_script.sh
😊 Thanks for reading.
Note : If you see any issues or wrong instruction with this article, please feel free to contact with me by comments or mail: hello@rathik.dev