MongoDB Database Backups

This tutorial shows how to backup your Jelastic MongoDB database automatically using cron.

A. Create environment

    1. Log in to
      Jelastic Manager
    2. Click Create environment.

    3. mongodb environment

    4. In the Environment topology window select MongoDB as a database you want to use. After that set the cloudlet limit, state the environment name and click Create.

    5. create mongodb

    6. Wait just a minute for your environment to be created.

    7. B. Configure backups

    1. Click the Config button next to your database.

    2. mongodb backup

    3. Navigate to the scripts folder and open the backup_script.sh file. In this file find the following line and state your values:

    4. MONGO_USERNAME="admin";
      MONGO_PASSWORD=" <YOUR MONGO PASSWORD> ";
      DAYS_TO_STORE=3;

      <MONGO_USERNAME> and <MONGO_PASSWORD> are your database username and password which you received via email after adding MongoDB.

      <DAYS_TO_STORE> is the period of storing the backup files (the default value is 3)

      Save the changes.

      mongo cron

    5. Open the cron folder and choose the mongod file.
      Uncomment the following line:
    6. @daily /bin/bash /var/lib/jelastic/bin/backup_script.sh

      Save the changes.
      As a result your database will be backed up once per day (at night) according to the default configurations.

      mongo backup script

      If you'd like to backup your database with the other frequency, you need to configure how often the script should run. To do this add the cron settings instead of the default value (@daily).

      For example, if you prefer to backup your database every ten minutes this string will be as follows:

      */10 * * * * /bin/bash /var/lib/jelastic/bin/backup_script.sh

      Save the changes.

      mongo cron settings

    7. You can also configure the backup of specific databases.

      To do this navigate to the scripts folder, open the backup_script.sh file and uncomment the following string as it is shown below:

      # DATABASES_LIST=("db1" "db2"); ###


    8. backup database

      Paste the names of databases you want to backup instead of "db*" values (separated with space) and Save the changes made.


    1. C. Checking backups

    1. Wait the time of the backup you've scheduled while setting.

    2. Navigate to the Configuration tab and open the backup folder (/var/lib/jelastic/backup). There .tgz files with all executed backups are stored.

    3. backup mongo

    4. D. Download Backup

    1. Install FTP for your database server. Find detailed instructions in the FTP/FTPS Support guide.

    2. backup download

    3. Connect to MongoDB using FTP client (e.g. FileZilla) and download your backup .tgz archive.

    4. json

    5. E. Restore database from a backup

    1. Unzip the downloaded backup package.

    2. Open the folder with the name of the database or the collection you'd like to restore and find the collection .bson file.

    3. Convert bson file into the json format running the following command:
    4. bsondump my.bson > my.json

      Note: You need to install MongoDB on your local machine. Place the bson file to the mongodb.../bin folder and run the above mentioned command under this directory. The generated json file will be stored in the same folder.

    5. Access the RockMongo admin panel with the credentials you've got after adding MongoDB.

    6. Navigate to the existing database to restore the data in it or create a new one.

    7. Open the Import tab and download your json file stating the collection where you want to place it.

    8. mongo restore

      As a result you can see that all your data is successfully restored.