Install MongoDB and Elastic Search and Restore Backup Data using Terminal
Welcome again, Hope you are doing well.
In this tutorial I shall tell the steps required to install MongoDB, Elastic Search and how to restore backup data in MongoDB so let’s start.
a) Download MongoDB is one step process
sudo apt install mongodb
Now be prepare for elastic search installation and follow the following commands
b) Install apt-transport-https
sudo apt-get install apt-transport-https
c) Get the elasticsearch package from internet
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.7.1-amd64.deb
d) Get the secured hashed (sha-512) package
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.7.1-amd64.deb.sha512
e) Compare the SHA of the downloaded Debian package and the published checksum
shasum -a 512 -c elasticsearch-7.7.1-amd64.deb.sha512
f) Finally install downloaded debian package
sudo dpkg -i elasticsearch-7.7.1-amd64.deb
g) To start Elastic Search
sudo -i service elasticsearch start
h) To start MongoDB
sudo service mongodb start
Till Now Installation of MongoDB and Elastic Search has been done.
Now we will see how to Restore any backup data stored in MongoDB again.
i) So after starting MongoDB type ‘mongo’ and it will open an interactive mongo shell where you can write mongodb commands/queries.
After coming in the mongo shell first drop the production database present there.
This is three step as shown below:
- First is open mongo shell using following
mongo
- When mongo shell is opened the list all databases present there using following
show dbs
- If Production database is present there then first drop it
use production
db.dropDatabase()
j) After dropping the production database exit the mongo shell using CTRL+C and restore Production database with your data. You have to provide the path of data where data is present.
mongorestore -d production path_of_data_where_it_is_present
Now you are ready to go.
Thank You!