Skip to main content
This script backs up the MongoDB database and stores it in the /opt/mongoyedek folder. If there are multiple backups, it keeps the newest 2 and deletes the others.
If you are going to use this script, first set it up in your test environment and follow it for a period you find appropriate.
To prevent the server’s disk from filling up in case there are too many old backups or they are not deleted, either define a separate disk space for the address where you will take backups, or also consider moving backups to a location outside the server.
Edit the ,, fields specified for the script according to your own Db information.

Script Creation

Script Content

Running Script

Automatic Execution (Cron)

If you wish, you can ensure that the script runs at a specific time or time period. Cron can be used for this.
Add the line below to the opened file.
In the example usage, the script will run on the 1st day of each month at 23:59.