This tutorial shows how to backup your GPUonCLOUD MongoDB database automatically using the Cron.

A. Create environment:-

      • Log in toGPUonCLOUD Manager

      • Click Create environment.

            mongodb environment

 

      • 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.


            

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

B. Configure backups:-

      • Click the Config button next to your database.


            
mongodb backup

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


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.

          

      • Open the cron folder and choose the mongod file.
        Uncomment the following line:

@daily /bin/bash /var/lib/gpuoncloud/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.

          
If you’d like to back up 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/gpuoncloud/bin/backup_script.sh

Save the changes.
            

      • 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”); ###

                   

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

C. Checking backups:-

      • Wait the time of the backup you’ve scheduled while setting.

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


         
backup mongo

D. Download Backup:-

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


            

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

            json

E. Restore database from a backup:-

    • Unzip the downloaded backup package.

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

    • Convert bson file into the json format running the following command:

  • 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.

    • Access the RockMongo admin panel with the credentials you’ve got after adding MongoDB.

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

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


         
mongo restore

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