This tutorial shows how to backup your Jelastic MongoDB database automatically using cron.
A. Create environment
- Log in toJelastic Manager
- Click Create 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.
- Click the Config button next to your database.
- Navigate to the scripts folder and open the backup_script.sh file. In this file find the following line and state your values:
- Open the cron folder and choose the mongod file.
Uncomment the following line:
- 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"); ###
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/jelastic/backup). There .tgz files with all executed backups are stored.
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.
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:
- 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.
B. Configure backups
MONGO_PASSWORD=" <YOUR MONGO PASSWORD> ";
<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.
@daily /bin/bash /var/lib/jelastic/bin/backup_script.shSave 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 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.shSave the changes.
Paste the names of databases you want to backup instead of "db*" values (separated with space) and Save the changes made.
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.
As a result you can see that all your data is successfully restored.